home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #1 / Amiga Plus CD - 2000 - No. 1.iso / Tools / Dev / Meshwriter / meshwriter.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-12-03  |  110.8 KB  |  4,261 lines

  1. /*
  2. **      $VER: meshwriter.c 0.02 (28.3.1999)
  3. **
  4. **      Creation date     : 18.10.1998
  5. **
  6. **      Description       :
  7. **         Mesh writer functions module
  8. **
  9. **
  10. **      Written by Stephan Bielmann
  11. **
  12. */
  13.  
  14. #define __USE_SYSBASE        // perhaps only recognized by SAS/C
  15.  
  16. /*************************** Includes *******************************/
  17.  
  18. /*
  19. ** ANSI standart includes
  20. */
  21. #include <string.h>
  22. #include <math.h>
  23.  
  24. /*
  25. ** Amiga includes
  26. */
  27. #include <exec/types.h>
  28. #include <exec/memory.h>
  29. #include <dos/stdio.h>
  30.  
  31. #include <clib/dos_protos.h>
  32. #include <clib/alib_stdio_protos.h>
  33.  
  34. #include <pragma/exec_lib.h>
  35.  
  36. /*
  37. ** Project includes
  38. */
  39. #include <meshwriter_private.h>
  40.  
  41. #include "raw.h"
  42. #include "vrml1.h"
  43. #include "dxf.h"
  44. #include "pov3.h"
  45. #include "imagine.h"
  46. #include "reflections.h"
  47. #include "lightwave.h"
  48. #include "geo.h"
  49. //#include "real.h"
  50. //#include "postscript.h"
  51.  
  52. #include "compiler.h"
  53.  
  54. /********************** Private constants ***************************/
  55.  
  56. /*
  57. ** The constant supported file format arrays
  58. */
  59. static ULONG  c3dFFIDs [] = {
  60.     T3DFDXF,
  61.     T3DFTDDD,
  62.     T3DFTDDDH,
  63.     T3DFLWOB,
  64.     T3DFPOV3,
  65.     T3DFRAWA,
  66.     T3DFRAWB,
  67. //    T3DFREAL,
  68.     T3DFREF4,
  69.     T3DFGEOA,
  70.     T3DFVRML1,
  71.     0
  72. };
  73.  
  74. static STRPTR c3dFFNames [] = {
  75.     "AutoCAD DXF",
  76.     "Imagine original",
  77.     "Imagine huge",
  78.     "Lightwave",
  79.     "POVRay 3.X",
  80.     "RAW ASCII",
  81.     "RAW binary",
  82. //    "Real 3D",
  83.     "Reflections 4.X",
  84.     "Videoscape ASCII",
  85.     "VRML 1",
  86.     NULL
  87. };
  88.  
  89. static STRPTR c3dFFExtensions [] = {
  90.     "dxf",
  91.     "iob",
  92.     "iob",
  93.     "lwob",
  94.     "pov",
  95.     "raw",
  96.     "raw",
  97. //    "real",
  98.     "r4",
  99.     "geo",
  100.     "wrl",
  101.     NULL
  102. };
  103.  
  104. static ULONG  c2dFFIDs   [] = {
  105. //    T2DFEPS,
  106. //    T2DFPSP,
  107. //    T2DFPSL,
  108.     0
  109. };
  110.  
  111. static STRPTR c2dFFNames [] = {
  112. //    "Encapsulated PostScript",
  113. //    "PostScript portrait",
  114. //    "PostScript landscape",
  115.     NULL
  116. };
  117.  
  118. static STRPTR c2dFFExtensions [] = {
  119. //    "eps",
  120. //    "ps",
  121. //    "ps",
  122.     NULL
  123. };
  124.  
  125.  
  126. /*
  127. ** The constant supported drawing mode arrays
  128. */
  129. static ULONG  cDMIDs   [] = {
  130. //    TDMPOINTS,
  131. //    TDMGRIDBW,
  132. //    TDMGRIDGR,
  133. //    TDMGRIDCL,
  134. //    TDMSURFBW,
  135. //    TDMSURFGR,
  136. //    TDMSURFCL,
  137.     0
  138. };
  139.  
  140. static STRPTR  cDMNames   [] = {
  141. //    "Points, black and white",
  142. //    "Grid, black and white",
  143. //    "Grid, gray scales",
  144. //    "Grid, colors",
  145. //    "Surface, black and white",
  146. //    "Surface, gray scales",
  147. //    "Surface, colors",
  148.     0
  149. };
  150.  
  151. /*
  152. ** Definition of PI
  153. */
  154. #define PI 3.14159265359
  155.  
  156. /********************** Private functions ***************************/
  157.  
  158. /********************************************************************\
  159. *                                                                    *
  160. * Name         : hash                                                *
  161. *                                                                    *
  162. * Description  : Calculates the hashcode of a vertex.                *
  163. *                                                                    *
  164. * Arguments    : vertex IN : The vertex to hash.                     *
  165. *                                                                    *
  166. * Return Value : hashcode                                            *
  167. *                                                                    *
  168. * Comment      :                                                     *
  169. *                                                                    *
  170. \********************************************************************/
  171. static ULONG hash(TOCLVertex vertex) {
  172.     DOUBLE  hx = vertex.x*12.3;
  173.     DOUBLE  hy = vertex.y*23.4;
  174.     DOUBLE  hz = vertex.z*34.5;
  175.  
  176.     return (((ULONG) (pow(hx*hx + hy*hy + hz*hz,0.5) * 9.87)) % HASHSIZE);
  177. }
  178.  
  179. /********************************************************************\
  180. *                                                                    *
  181. * Name         : addVertex                                           *
  182. *                                                                    *
  183. * Description  : Adds the vertex to the mesh, if not already in its  *
  184. *                internal list. And returns the pointer to it.       *
  185. *                The vertex will be transformed according the mehs   *
  186. *                its CTM.
  187. *                                                                    *
  188. * Arguments    : mesh   IN : Pointer to the mesh.                    *
  189. *                vertex IN : The vertex to add.                      *
  190. *                                                                    *
  191. * Return Value : Pointer to the "new" vertex or NULL if no more      *
  192. *                memory is available.                                *
  193. *                                                                    *
  194. * Comment      :                                                     *
  195. *                                                                    *
  196. \********************************************************************/
  197. static TOCLVertexNode *addVertex(TOCLMesh *mesh,
  198.                                  TOCLVertex vertex) {
  199.  
  200.     ULONG    hashcode        =hash(vertex);
  201.     TOCLHashsVerticesNode    *hlvindex=NULL;
  202.     TOCLVertexNode            *ver=NULL;
  203.     TOCLCTM                ctm;
  204.     TOCLVertex             rvertex;
  205.  
  206.     ctm=mesh->ctm;
  207.  
  208.     /*
  209.     ** Transforming the the vertex according the CTM
  210.     */
  211.     // Scaling
  212.     vertex.x*=ctm.sx,vertex.y*=ctm.sy,vertex.z*=ctm.sz;
  213.  
  214.     //Rotation and translation
  215.     rvertex.x=ctm.m[0][0]*vertex.x+ctm.m[1][0]*vertex.y+ctm.m[2][0]*vertex.z+ctm.m[3][0]; 
  216.     rvertex.y=ctm.m[0][1]*vertex.x+ctm.m[1][1]*vertex.y+ctm.m[2][1]*vertex.z+ctm.m[3][1]; 
  217.     rvertex.z=ctm.m[0][2]*vertex.x+ctm.m[1][2]*vertex.y+ctm.m[2][2]*vertex.z+ctm.m[3][2]; 
  218.  
  219.     /*
  220.     ** Check if the vertex is already in our internal list
  221.     */
  222.     hlvindex=mesh->hashTable[hashcode];
  223.     while(hlvindex!=NULL)
  224.     {
  225.           ver=hlvindex->vertexNode;
  226.  
  227.         if(rvertex.x==ver->vertex.x &&
  228.            rvertex.y==ver->vertex.y &&
  229.            rvertex.z==ver->vertex.z ) {
  230.             /*
  231.             ** Yes, return its pointer
  232.             */
  233.             return (ver);
  234.         }
  235.         hlvindex=hlvindex->next;
  236.     }
  237.     
  238.     /*
  239.     ** No it was not. Add a new one to the list and hash and return it
  240.     */
  241.     ver = AllocPooled(mesh->vertexpool,sizeof(TOCLVertexNode));
  242.     if (ver==NULL) return(NULL);
  243.     
  244.     /* The index begins at 1 ! */
  245.     mesh->vertices.numberOfVertices++;            /* increment the list counter */
  246.     ver->index=mesh->vertices.numberOfVertices;    /* Set the index */
  247.     ver->vertex = rvertex;
  248.     ver->next=NULL;
  249.  
  250.     if(mesh->vertices.firstNode!=NULL) {   /* Check if this is the first vertex to insert or not */
  251.         mesh->vertices.lastNode->next=ver;
  252.         mesh->vertices.lastNode=ver;
  253.     }
  254.     else {
  255.         mesh->vertices.lastNode=ver;
  256.         mesh->vertices.firstNode=ver;
  257.     }
  258.  
  259.     /*
  260.     ** Recalculate the bounding box
  261.     */
  262.     if(vertex.x<mesh->bBox.left)   mesh->bBox.left=rvertex.x;
  263.     if(vertex.x>mesh->bBox.right)  mesh->bBox.right=rvertex.x;
  264.     if(vertex.y<mesh->bBox.rear)   mesh->bBox.rear=rvertex.y;
  265.     if(vertex.y>mesh->bBox.front)  mesh->bBox.front=rvertex.y;
  266.     if(vertex.z<mesh->bBox.bottom) mesh->bBox.bottom=rvertex.z;
  267.     if(vertex.z>mesh->bBox.top)    mesh->bBox.top=rvertex.z;
  268.     
  269.     /*
  270.     ** Add the vertex to the hash table
  271.     */
  272.     hlvindex = AllocMem(sizeof(TOCLHashsVerticesNode),MEMF_FAST);
  273.     if (hlvindex==NULL) {
  274.         FreePooled(mesh->vertexpool,ver,sizeof(TOCLVertexNode));
  275.         return(NULL);
  276.     }
  277.     
  278.     hlvindex->vertexNode=ver;
  279.     hlvindex->next=mesh->hashTable[hashcode];
  280.     mesh->hashTable[hashcode]=hlvindex;
  281.     
  282.     return(ver);
  283. }
  284.  
  285. /********************************************************************\
  286. *                                                                    *
  287. * Name         : getVertex                                           *
  288. *                                                                    *
  289. * Description  : Search a vertex in the list with its index.         *
  290. *                                                                    *
  291. * Arguments    : mesh   IN : Pointer to the mesh.                    *
  292. *                index  IN : The vertex its index.                   *
  293. *                                                                    *
  294. * Return Value : Pointer to the vertex or NULL if not found.         *
  295. *                                                                    *
  296. * Comment      :                                                     *
  297. *                                                                    *
  298. \********************************************************************/
  299. static TOCLVertexNode *getVertex(TOCLMesh *mesh,
  300.                                 ULONG index) {
  301.  
  302.     TOCLVertexNode            *ver=NULL;
  303.  
  304.     if(index==0) return(NULL);
  305.  
  306.     ver=mesh->vertices.firstNode;
  307.     while(ver!=NULL && ver->index!=index) {
  308.         ver=ver->next;
  309.     }
  310.  
  311.     return(ver);
  312. }
  313.  
  314. /********************************************************************\
  315. *                                                                    *
  316. * Name         : getVertexIndex                                      *
  317. *                                                                    *
  318. * Description  : Search the index of a vertex in the list with its   *
  319. *                coordinates.                                        *
  320. *                                                                    *
  321. * Arguments    : mesh   IN : Pointer to the mesh.                    *
  322. *                vertex IN : The vertex to search for.               *
  323. *                                                                    *
  324. * Return Value : Index to the vertex or 0 if not found.              *
  325. *                                                                    *
  326. * Comment      :                                                     *
  327. *                                                                    *
  328. \********************************************************************/
  329. static ULONG getVertexIndex(TOCLMesh *mesh,
  330.                             TOCLVertex vertex) {
  331.  
  332.     ULONG    hashcode        =hash(vertex);
  333.     TOCLHashsVerticesNode    *hlvindex=NULL;
  334.     TOCLVertexNode            *ver=NULL;
  335.  
  336.     /*
  337.     ** Check if the vertex is already in our internal list
  338.     */
  339.     hlvindex=mesh->hashTable[hashcode];
  340.     while(hlvindex!=NULL)
  341.     {
  342.           ver=hlvindex->vertexNode;
  343.  
  344.         if(vertex.x==ver->vertex.x &&
  345.            vertex.y==ver->vertex.y &&
  346.            vertex.z==ver->vertex.z ) {
  347.             /*
  348.             ** Yes, return its index
  349.             */
  350.             return (ver->index);
  351.         }
  352.         hlvindex=hlvindex->next;
  353.     }
  354.     
  355.     /*
  356.     ** No it was not.
  357.     */
  358.     return(0);
  359. }
  360.  
  361. /********************************************************************\
  362. *                                                                    *
  363. * Name         : getMaterialNode                                     *
  364. *                                                                    *
  365. * Description  : Search the material its node with its index, in     *
  366. *                the given mesh. If the index=0 or not valid, NULL   *
  367. *                will be returned.                                   *
  368. *                                                                    *
  369. * Arguments    : mesh          IN : Pointer to the mesh.             *
  370. *                materialindex IN : Material index.                  *
  371. *                                                                    *
  372. * Return Value : Pointer to the material or NULL if not found.       *
  373. *                                                                    *
  374. * Comment      :                                                     *
  375. *                                                                    *
  376. \********************************************************************/
  377. static TOCLMaterialNode *getMaterialNode(TOCLMesh *mesh, ULONG materialindex) {
  378.     TOCLMaterialNode    *mindex=NULL;
  379.     
  380.     if(materialindex==0 || materialindex>mesh->materials.numberOfMaterials) return(NULL);
  381.     
  382.     /*
  383.     ** Search the material
  384.     */
  385.     mindex=mesh->materials.firstNode;
  386.     while(mindex!=NULL) {
  387.         if(mindex->index==materialindex) return(mindex);
  388.         
  389.         mindex=mindex->next;
  390.     }
  391.  
  392.     /*
  393.     ** Not found
  394.     */    
  395.     return(NULL);
  396. }
  397.  
  398. /********************************************************************\
  399. *                                                                    *
  400. * Name         : setCameraLight                                      *
  401. *                                                                    *
  402. * Description  : Sets the default position of the camera and the     *
  403. *                light and the camera its view point and the color   *
  404. *                of the light source.                                *
  405. *                                                                    *
  406. * Arguments    : mesh      IN/OUT : Pointer to the mesh.             *
  407. *                                                                    *
  408. * Comment      :                                                     *
  409. *                                                                    *
  410. \********************************************************************/
  411. static VOID setCameraLight(TOCLMesh *mesh) {
  412.     TOCLVertex ver1;
  413.         
  414.     if (mesh==NULL) return;
  415.  
  416.     /* camera its look at position */
  417.     mesh->camera.lookat.x = (mesh->bBox.left + mesh->bBox.right) / 2;
  418.     mesh->camera.lookat.y = (mesh->bBox.front + mesh->bBox.rear) / 2;
  419.     mesh->camera.lookat.z = (mesh->bBox.top + mesh->bBox.bottom) / 2;
  420.     
  421.     /* direction vector */
  422.     ver1.x = mesh->bBox.right - mesh->camera.lookat.x;
  423.     ver1.y = mesh->bBox.front - mesh->camera.lookat.y;
  424.     ver1.z = mesh->bBox.top - mesh->camera.lookat.z;
  425.     
  426.     ver1.x*=2.5;
  427.     ver1.y*=2.5;    
  428.     ver1.z*=2.5;
  429.     
  430.     /* camera its position */
  431.     mesh->camera.position.x = ver1.x + mesh->camera.lookat.x;
  432.     mesh->camera.position.y = ver1.y + mesh->camera.lookat.y;
  433.     mesh->camera.position.z = ver1.z + mesh->camera.lookat.z;
  434.  
  435.     /* light source its position */
  436.     mesh->light.position.x = ver1.x + mesh->camera.lookat.x;
  437.     mesh->light.position.y = ver1.x + mesh->camera.lookat.x;
  438.     mesh->light.position.z = ver1.x + mesh->camera.lookat.x;
  439.     
  440.     /* light source its color */
  441.     mesh->light.color.r=255;
  442.     mesh->light.color.g=255;
  443.     mesh->light.color.b=255;
  444. }
  445.  
  446. /********************************************************************\
  447. *                                                                    *
  448. * Name         : mul33Matrix                                         *
  449. *                                                                    *
  450. * Description  : Multiplicates two 3x3 matrix structures.            *
  451. *                                                                    *
  452. * Arguments    : m1  IN/OUT : The first matrix, contains the result  *
  453. *                m2  IN     : The second matrix.                     *
  454. *                                                                    *
  455. * Comment      :                                                     *
  456. *                                                                    *
  457. \********************************************************************/
  458. void mulMatrix (double m1[3][3], double m2[3][3]) {
  459.     double m[3][3];
  460.     int x,y,yy;
  461.  
  462.     for(x=0;x<3;x++) {
  463.         for(y=0;y<3;y++) {
  464.             m[x][y]=0;
  465.         }
  466.     }
  467.  
  468.     for(x=0;x<3;x++) {
  469.         for(y=0;y<3;y++) {
  470.             for(yy=0;yy<3;yy++) {
  471.                 m[x][y]+=m1[yy][y]*m2[x][yy];
  472.             }
  473.         }
  474.     }
  475.  
  476.     m1[0][0]=m[0][0];
  477.     m1[1][0]=m[1][0];
  478.     m1[2][0]=m[2][0];
  479.     m1[0][1]=m[0][1];
  480.     m1[1][1]=m[1][1];
  481.     m1[2][1]=m[2][1];
  482.     m1[0][2]=m[0][2];
  483.     m1[1][2]=m[1][2];
  484.     m1[2][2]=m[2][2];
  485. }
  486.  
  487. /********************** Public functions ****************************/
  488.  
  489. /****** meshwriter.library/MWLMeshNew ******************************************
  490. *   NAME    
  491. *     MWLMeshNew -- Creates a new mesh
  492. *   SYNOPSIS
  493. *    meshhandle = MWLMeshNew( )
  494. *              
  495. *
  496. *    ULONG MWLMeshNew
  497. *         ( );
  498. *
  499. *   FUNCTION
  500. *    Allocates the memory for a new mesh, initializes all its contents and
  501. *    returns a handle to the new mesh. The mesh has to be deleted after usage
  502. *    with MWLMeshDelete().   
  503. *
  504. *   INPUTS
  505. *   RESULT
  506. *     meshhandle - A handle to the new mesh, or 0 in error case, which means
  507. *                 that there is not enough memory available.
  508. *   EXAMPLE
  509. *
  510. *   NOTES
  511. *
  512. *   BUGS
  513. *   SEE ALSO
  514. *     MWLMeshDelete()
  515. *
  516. *****************************************************************************
  517. *
  518. */
  519. ULONG __saveds ASM MWLMeshNew() {
  520.     TOCLMesh     *mesh=NULL;
  521.     LONG        i;
  522.     UBYTE        buffer[10];
  523.  
  524.     mesh = AllocMem(sizeof(TOCLMesh),MEMF_FAST);
  525.     if (mesh==NULL) return(0);
  526.  
  527.     // create a memory pool for the vertices of this this header
  528.     // ground size of a pool is to get 100 vertices
  529.     mesh->vertexpool=CreatePool(MEMF_FAST,100*sizeof(TOCLVertexNode),100*sizeof(TOCLVertexNode));
  530.     if(mesh->vertexpool==NULL) {
  531.         FreeMem(mesh,sizeof(TOCLMesh));
  532.         return(0);
  533.     }
  534.  
  535.     // create a memory pool for the polygon nodes of this this header
  536.     // ground size of a pool is to get 100 polygons
  537.     mesh->polygonpool=CreatePool(MEMF_FAST,100*sizeof(TOCLPolygonNode),100*sizeof(TOCLPolygonNode));
  538.     if(mesh->polygonpool==NULL) {
  539.         DeletePool(mesh->vertexpool);
  540.         FreeMem(mesh,sizeof(TOCLMesh));
  541.         return(0);
  542.     }
  543.  
  544.     // create a memory pool for the polygon vertex nodes of this this header
  545.     // ground size of a pool is to get 100 polygon vertices
  546.     mesh->polygonverticespool=CreatePool(MEMF_FAST,100*sizeof(TOCLPolygonsVerticesNode),100*sizeof(TOCLPolygonsVerticesNode));
  547.     if(mesh->polygonverticespool==NULL) {
  548.         DeletePool(mesh->polygonpool);
  549.         DeletePool(mesh->vertexpool);
  550.         FreeMem(mesh,sizeof(TOCLMesh));
  551.         return(0);
  552.     }
  553.  
  554.     mesh->name=NULL;
  555.     strcpy(buffer,"NONAME");
  556.     mesh->name = AllocVec(strlen(buffer)+1,MEMF_FAST);
  557.     if (mesh->name==NULL) {
  558.         DeletePool(mesh->polygonverticespool);
  559.         DeletePool(mesh->polygonpool);
  560.         DeletePool(mesh->vertexpool);
  561.         FreeMem(mesh,sizeof(TOCLMesh));
  562.         return(0);
  563.     }
  564.     strcpy(mesh->name,buffer);
  565.     
  566.     mesh->copyright=NULL;
  567.  
  568.     mesh->bBox.left=0.0;
  569.     mesh->bBox.right=0.0;
  570.     mesh->bBox.front=0.0;
  571.     mesh->bBox.rear=0.0;
  572.     mesh->bBox.top=0.0;
  573.     mesh->bBox.bottom=0.0;
  574.     
  575.     mesh->camera.position.x=0.0;
  576.     mesh->camera.position.y=0.0;
  577.     mesh->camera.position.z=0.0;
  578.     mesh->camera.lookat.x=0.0;
  579.     mesh->camera.lookat.y=0.0;
  580.     mesh->camera.lookat.z=0.0;
  581.     
  582.     mesh->light.position.x=0.0;
  583.     mesh->light.position.y=0.0;
  584.     mesh->light.position.z=0.0;
  585.     mesh->light.color.r=255;
  586.     mesh->light.color.g=255;
  587.     mesh->light.color.b=255;
  588.         
  589.     mesh->vertices.numberOfVertices=0;
  590.     mesh->vertices.firstNode=NULL;
  591.     mesh->vertices.lastNode=NULL;
  592.         
  593.     mesh->polygons.numberOfPolygons=0;
  594.     mesh->polygons.firstNode=NULL;
  595.     mesh->polygons.lastNode=NULL;
  596.     
  597.     mesh->materials.numberOfMaterials=0;
  598.     mesh->materials.firstNode=NULL;
  599.     mesh->materials.lastNode=NULL;
  600.  
  601.     mesh->ctm.sx=1,mesh->ctm.sy=1,mesh->ctm.sz=1;
  602.     mesh->ctm.rx=0,mesh->ctm.ry=0,mesh->ctm.rz=0;
  603.     mesh->ctm.m[0][0]=1,mesh->ctm.m[1][0]=0,mesh->ctm.m[2][0]=0,mesh->ctm.m[3][0]=0;
  604.     mesh->ctm.m[0][1]=0,mesh->ctm.m[1][1]=1,mesh->ctm.m[2][1]=0,mesh->ctm.m[3][1]=0;
  605.     mesh->ctm.m[0][2]=0,mesh->ctm.m[1][2]=0,mesh->ctm.m[2][2]=1,mesh->ctm.m[3][2]=0;
  606.     mesh->ctm.m[0][3]=0,mesh->ctm.m[1][3]=0,mesh->ctm.m[2][3]=0,mesh->ctm.m[3][3]=1;
  607.     
  608.     for(i=0;i<HASHSIZE;i++) mesh->hashTable[i]=NULL;
  609.     
  610.     return(ULONG)mesh;
  611. }
  612.  
  613. /****** meshwriter.library/MWLMeshDelete ******************************************
  614. *   NAME    
  615. *     MWLMeshDelete -- Delete a mesh which was created whith MWLMeshNew() before.
  616. *   SYNOPSIS
  617. *    error = MWLMeshDelete( meshhandle )
  618. *                           D1
  619. *
  620. *    ULONG MWLMeshDelete
  621. *         ( ULONG );
  622. *
  623. *   FUNCTION
  624. *    Free the memory occupied by the mesh, and delete the mesh itself.
  625. *   INPUTS
  626. *     meshhandle    - A valid handle of a mesh.
  627. *    
  628. *   RESULT
  629. *     error - RCNOERROR if all went well.
  630. *            RCNOMESH  if the handle is not valid.
  631. *
  632. *   EXAMPLE
  633. *   NOTES
  634. *    Can take some time.
  635. *
  636. *   BUGS
  637. *   SEE ALSO
  638. *     MWLMeshNew()
  639. ******************************************************************************
  640. *
  641. */
  642. ULONG __saveds ASM MWLMeshDelete(register __d1 ULONG meshhandle) {
  643.     TOCLMesh                    *mesh=NULL;
  644.     TOCLVertexNode                *ver=NULL, *vindex=NULL;
  645.     TOCLPolygonNode            *pln=NULL, *plnindex=NULL;
  646.     TOCLPolygonsVerticesNode    *plv=NULL, *plvindex=NULL;
  647.     TOCLMaterialNode            *mat=NULL, *mindex=NULL;
  648.     TOCLHashsVerticesNode        *hlv=NULL, *hlvindex=NULL;
  649.     ULONG                        i;
  650.         
  651.     mesh=(TOCLMesh *) meshhandle;
  652.     if(mesh==NULL) return(RCNOMESH);
  653.  
  654.     /*
  655.     ** Free the name string
  656.     */
  657.     FreeVec(mesh->name);
  658.  
  659.     /*
  660.     ** Free the copyright string
  661.     */ 
  662.     FreeVec(mesh->copyright);
  663.  
  664.     /*
  665.     ** Free the vertices
  666.     */
  667.     DeletePool(mesh->vertexpool);
  668.  
  669.     /*
  670.     ** Free the polygon vertices
  671.     */
  672.     DeletePool(mesh->polygonverticespool);
  673.  
  674.     /*
  675.     ** Free the polygons
  676.     */
  677.     DeletePool(mesh->polygonpool);
  678.     
  679.     /*
  680.     ** Free the materials
  681.     */
  682.     mindex=mesh->materials.firstNode;
  683.     while(mindex!=NULL) {
  684.         mat=mindex;
  685.         mindex=mindex->next;
  686.         
  687.         /*
  688.         ** Free the name string
  689.         */
  690.         FreeVec(mat->name);
  691.         
  692.         FreeMem(mat,sizeof(TOCLMaterialNode));
  693.     }
  694.  
  695.     /*
  696.     ** Free the hashtable entries
  697.     */
  698.     for(i=0;i<HASHSIZE;i++) {
  699.         hlvindex=mesh->hashTable[i];
  700.         while(hlvindex!=NULL) {
  701.             hlv=hlvindex;
  702.             hlvindex=hlvindex->next;
  703.             FreeMem(hlv,sizeof(TOCLHashsVerticesNode));
  704.         }        
  705.     }
  706.  
  707.     /*
  708.     ** Free the mesh itself
  709.     */
  710.     FreeMem(mesh,sizeof(TOCLMesh));
  711.  
  712.     return(RCNOERROR);
  713. }
  714.  
  715. /****** meshwriter.library/MWLMeshNameSet ******************************************
  716. *   NAME    
  717. *     MWLMeshNameSet -- Set the name of the mesh.
  718. *   SYNOPSIS
  719. *    error = MWLMeshNameSet( meshhandle,name )
  720. *                            D1         D2
  721. *
  722. *    ULONG MWLMeshNameSet
  723. *         ( ULONG,STRPTR );
  724. *
  725. *   FUNCTION
  726. *    A copy of the passed string will be made and assigned to the mesh its
  727. *    name string.
  728. *   INPUTS
  729. *     meshhandle      - A valid handle of a mesh.
  730. *    name            - String which contains the name.
  731. *    
  732. *   RESULT
  733. *     error - RCNOERROR  if all went well.
  734. *            RCNOMESH   if the handle is not valid.
  735. *             RCNOMEMORY if there is not enough memory.
  736. *
  737. *   EXAMPLE
  738. *    error = MWLMeshNameSet(meshhandle,"GreatShape");
  739. *
  740. *   NOTES
  741. *    This function can be called as often as you need, which will
  742. *    replace the old value.
  743. *
  744. *    Not all formats support names, and the written length of the
  745. *    string depends of the format too.
  746. *
  747. *   BUGS
  748. *   SEE ALSO
  749. *     MWLMeshNameGet()
  750. ******************************************************************************
  751. *
  752. */
  753. ULONG __saveds ASM MWLMeshNameSet(register __d1 ULONG meshhandle,register __d2 STRPTR name ) {
  754.     TOCLMesh *mesh=NULL;
  755.   
  756.     mesh=(TOCLMesh *) meshhandle;
  757.     if (mesh==NULL) return(RCNOMESH);
  758.  
  759.     /*
  760.     ** If the name was already set before, free it
  761.     */
  762.     if (mesh->name) FreeVec(mesh->name);
  763.     mesh->name=NULL;
  764.  
  765.     mesh->name=(STRPTR) AllocVec(strlen(name)+1,MEMF_FAST);
  766.     if(mesh->name==NULL) return(RCNOMEMORY);
  767.   
  768.     strcpy(mesh->name,name);
  769.   
  770.     return(RCNOERROR);
  771. }
  772.  
  773. /****** meshwriter.library/MWLMeshNameGet ******************************************
  774. *   NAME    
  775. *     MWLMeshNameGet -- Get the name of a mesh.
  776. *
  777. *   SYNOPSIS
  778. *    error = MWLMeshNameGet( meshhandle,name )
  779. *                            D1         D2
  780. *
  781. *    ULONG MWLMeshNameGet
  782. *         ( ULONG,STRPTR * );
  783. *
  784. *   FUNCTION
  785. *    You will get a pointer to the name of the mesh. This string is READ_ONLY
  786. *    and only valid as long the as mesh exists.
  787. *   INPUTS
  788. *     meshhandle    - A valid handle of a mesh.
  789. *    name          - Pointer to the name of the mesh.
  790. *    
  791. *   RESULT
  792. *     error - RCNOERROR if all went well.
  793. *            RCNOMESH  if the handle is not valid.
  794. *   EXAMPLE
  795. *    error = MWLMeshNameGet(meshhandle,&mystring);
  796. *
  797. *   NOTES
  798. *
  799. *   BUGS
  800. *   SEE ALSO
  801. *     MWLMeshNameSet()
  802. ******************************************************************************
  803. *
  804. */
  805. ULONG __saveds ASM MWLMeshNameGet(register __d1 ULONG meshhandle, register __d2 STRPTR *name) {
  806.     TOCLMesh *mesh=NULL;
  807.   
  808.     mesh=(TOCLMesh *) meshhandle;
  809.     if (mesh==NULL) return(RCNOMESH);
  810.  
  811.     (*name)=mesh->name;
  812.  
  813.     return(RCNOERROR);
  814. }
  815.  
  816. /****** meshwriter.library/MWLMeshCopyrightSet ******************************************
  817. *   NAME    
  818. *     MWLMeshCopyrightSet -- Set the copyright of the mesh.
  819. *   SYNOPSIS
  820. *    error = MWLMeshCopyrightSet( meshhandle,copyright )
  821. *                                 D1         D2
  822. *
  823. *    ULONG MWLMeshCopyrightSet
  824. *         ( ULONG,STRPTR );
  825. *
  826. *   FUNCTION
  827. *    A copy of the passed string will be made and assigned to the mesh its
  828. *    copyright string.
  829. *   INPUTS
  830. *     meshhandle      - A valid handle of a mesh.
  831. *    copyright       - String which contains the copyright.
  832. *    
  833. *   RESULT
  834. *     error - RCNOERROR  if all went well.
  835. *            RCNOMESH   if the handle is not valid.
  836. *             RCNOMEMORY if there is not enough memory.
  837. *
  838. *   EXAMPLE
  839. *    error = MWLMeshCopyrightSet(meshhandle,"This mesh was created with GreatShaper V2.0 for Beethoven");
  840. *
  841. *   NOTES
  842. *    This should be only a single line !
  843. *
  844. *    This function can be called as often as you need, which will replace
  845. *    the old value.
  846. *
  847. *    Not all formats support copyrights, and the written length of the
  848. *    string depends of the format too.
  849. *
  850. *   BUGS
  851. *   SEE ALSO
  852. *     MWLMeshCopyrightGet()
  853. ******************************************************************************
  854. *
  855. */
  856. ULONG __saveds ASM MWLMeshCopyrightSet(register __d1 ULONG meshhandle,register __d2 STRPTR copyright) {
  857.     TOCLMesh *mesh=NULL;
  858.   
  859.     mesh=(TOCLMesh *) meshhandle;
  860.     if (mesh==NULL) return(RCNOMESH);
  861.     
  862.     /*
  863.     ** If the copyright was already set before, free it
  864.     */
  865.     if (mesh->copyright) FreeVec(mesh->copyright);
  866.     mesh->copyright=NULL;
  867.   
  868.     mesh->copyright=(STRPTR) AllocVec(strlen(copyright)+1,MEMF_FAST);
  869.     if(mesh->copyright==NULL) return(RCNOMEMORY);
  870.   
  871.     strcpy(mesh->copyright,copyright);
  872.   
  873.     return(RCNOERROR);
  874. }
  875.  
  876. /****** meshwriter.library/MWLMeshCopyrightGet ******************************************
  877. *   NAME    
  878. *     MWLMeshCopyrightGet -- Get the copyright of a mesh.
  879. *
  880. *   SYNOPSIS
  881. *    error = MWLMeshCopyrightGet( meshhandle,copyright )
  882. *                                 D1         D2
  883. *
  884. *    ULONG MWLMeshCopyrightGet
  885. *         ( ULONG,STRPTR * );
  886. *
  887. *   FUNCTION
  888. *    You will get a pointer to the copyright of the mesh. This string is READ_ONLY
  889. *    and only valid as long as the mesh exists.
  890. *   INPUTS
  891. *     meshhandle    - A valid handle of a mesh.
  892. *    copyright     - Pointer to the copyright of the mesh.
  893. *    
  894. *   RESULT
  895. *     error - RCNOERROR if all went well.
  896. *            RCNOMESH  if the handle is not valid.
  897. *   EXAMPLE
  898. *    error = MWLMeshCopyrightGet(meshhandle,&mystring);
  899. *
  900. *   NOTES
  901. *
  902. *   BUGS
  903. *   SEE ALSO
  904. *     MWLMeshCopyrightSet()
  905. ******************************************************************************
  906. *
  907. */
  908. ULONG __saveds ASM MWLMeshCopyrightGet(register __d1 ULONG meshhandle, register __d2 STRPTR *copyright) {
  909.     TOCLMesh *mesh=NULL;
  910.   
  911.     mesh=(TOCLMesh *) meshhandle;
  912.     if (mesh==NULL) return(RCNOMESH);
  913.     
  914.     (*copyright)=mesh->copyright;
  915.     
  916.     return(RCNOERROR);
  917. }
  918.  
  919. /****** meshwriter.library/MWLMeshMaterialAdd ******************************************
  920. *   NAME    
  921. *     MWLMeshMaterialAdd -- Add a new material to the mesh.
  922. *
  923. *   SYNOPSIS
  924. *    error = MWLMeshMaterialAdd( meshhandle,materialhandle )
  925. *                                D1         D2
  926. *
  927. *    ULONG MWLMeshMaterialAdd
  928. *         ( ULONG,ULONG * );
  929. *
  930. *   FUNCTION
  931. *    A new material will be created and added to the mesh. You will get a handle to it.
  932. *    All material properties will be set to 0.
  933. *   INPUTS
  934. *     meshhandle     - A valid handle of a mesh.
  935. *    materialhandle - Pointer to a variable which will contain 
  936. *                     the handle to the new material.
  937. *    
  938. *   RESULT
  939. *     error - RCNOERROR  if all went well.
  940. *            RCNOMESH   if the handle is not valid.
  941. *            RCNOMEMORY if there is not enough memory. 
  942. *   EXAMPLE
  943. *    error = MWLMeshMaterialAdd(meshhandle,&mylong);
  944. *
  945. *   NOTES
  946. *    A default name will be assigned to the new material.
  947. *    Like MWLMATX, where X is an internal count of the material.
  948. *
  949. *   BUGS
  950. *   SEE ALSO
  951. *     MWLMeshMaterialNameSet(),MWLMeshMaterialAmbientColorSet(),
  952. *   MWLMeshMaterialDiffuseColorSet(),MWLMeshMaterialShininessSet()
  953. *    MWLMeshMaterialTransparencySet()
  954. ******************************************************************************
  955. *
  956. */
  957. ULONG __saveds ASM MWLMeshMaterialAdd(register __d1 ULONG meshhandle, register __d2 ULONG *materialhandle) {
  958.     TOCLMesh            *mesh=NULL;
  959.     TOCLMaterialNode    *mat=NULL;
  960.     UBYTE                buffer[100];
  961.     
  962.     mesh=(TOCLMesh *) meshhandle;
  963.     if(mesh==NULL) return(RCNOMESH);
  964.  
  965.     (*materialhandle)=0;
  966.  
  967.     mat = AllocMem(sizeof(TOCLMaterialNode),MEMF_FAST);
  968.     if (mat==NULL) return(RCNOMEMORY);
  969.  
  970.     mat->index=++mesh->materials.numberOfMaterials; /*Index begins at 1 */
  971.    (*materialhandle)=mat->index;
  972.  
  973.     mat->name=NULL;
  974.     sprintf(buffer,"MWLMAT%ld",mat->index);
  975.     mat->name = AllocVec(strlen(buffer)+1,MEMF_FAST);
  976.     if (mat->name==NULL) {
  977.         FreeMem(mat,sizeof(TOCLMaterialNode));
  978.         return(RCNOMEMORY);
  979.     }
  980.     strcpy(mat->name,buffer);
  981.     
  982.     mat->ambientColor.r=0;
  983.     mat->ambientColor.g=0;
  984.     mat->ambientColor.b=0;
  985.     mat->diffuseColor.r=0;
  986.     mat->diffuseColor.g=0;
  987.     mat->diffuseColor.b=0;
  988.     mat->shininess=0;
  989.     mat->transparency=0;
  990.     mat->next=NULL;
  991.  
  992.     if(mesh->materials.firstNode!=NULL) {   /* Check if this is the first material to insert or not */
  993.         mesh->materials.lastNode->next=mat;
  994.         mesh->materials.lastNode=mat;
  995.     }
  996.     else {
  997.         mesh->materials.lastNode=mat;
  998.         mesh->materials.firstNode=mat;
  999.     }
  1000.  
  1001.     return(RCNOERROR);
  1002. }
  1003.  
  1004. /****** meshwriter.library/MWLMeshMaterialNameSet ******************************************
  1005. *   NAME    
  1006. *     MWLMeshMaterialNameSet -- Set the name of the material.
  1007. *   SYNOPSIS
  1008. *    error = MWLMeshMaterialNameSet( meshhandle,materialhandle,materialname )
  1009. *                                    D1         D2             D3
  1010. *
  1011. *    ULONG MWLMeshMaterialNameSet
  1012. *         ( ULONG,ULONG,STRPTR );
  1013. *
  1014. *   FUNCTION
  1015. *    A copy of the passed string will be made and assigned to the material its
  1016. *    name string.
  1017. *   INPUTS
  1018. *     meshhandle      - A valid handle of a mesh.
  1019. *    materialhandle  - A valid handle of a material.
  1020. *    materialname    - String which contains the name.
  1021. *    
  1022. *   RESULT
  1023. *     error - RCNOERROR    if all went well.
  1024. *            RCNOMESH     if the handle is not valid.
  1025. *            RCNOMATERIAL if the handle is not valid.
  1026. *             RCNOMEMORY   if there is not enough memory.
  1027. *
  1028. *   EXAMPLE
  1029. *    error = MWLMeshMaterialNameSet(meshhandle,materialhandle,"DeepBlue");
  1030. *
  1031. *   NOTES
  1032. *    This function can be called as often as you need which will
  1033. *    replace the old value.
  1034. *
  1035. *    Not all formats support names, and the written length of the
  1036. *    string depends of the format too.
  1037. *
  1038. *   BUGS
  1039. *   SEE ALSO
  1040. *     MWLMeshMaterialNameGet()
  1041. ******************************************************************************
  1042. *
  1043. */
  1044. ULONG __saveds ASM MWLMeshMaterialNameSet(register __d1 ULONG meshhandle,
  1045.                                                 register __d2 ULONG materialhandle,
  1046.                                                 register __d3 STRPTR materialname) {
  1047.     TOCLMesh            *mesh=NULL;
  1048.     TOCLMaterialNode    *mat=NULL;
  1049.   
  1050.     mesh=(TOCLMesh *) meshhandle;
  1051.     if(mesh==NULL) return(RCNOMESH);
  1052.  
  1053.     mat=getMaterialNode(mesh,materialhandle);
  1054.     if(mat==NULL) return(RCNOMATERIAL);
  1055.  
  1056.     /*
  1057.     ** If the name was already set before, free it
  1058.     */
  1059.     if (mat->name) FreeVec(mat->name);
  1060.     mat->name=NULL;
  1061.     
  1062.     mat->name=(STRPTR) AllocVec(strlen(materialname)+1,MEMF_FAST);
  1063.     if(mat->name==NULL) return(RCNOMEMORY);
  1064.   
  1065.     strcpy(mat->name,materialname);
  1066.  
  1067.     return(RCNOERROR);
  1068. }
  1069.  
  1070. /****** meshwriter.library/MWLMeshMaterialNameGet ******************************************
  1071. *   NAME    
  1072. *     MWLMeshMaterialNameGet -- Get the name of a material.
  1073. *
  1074. *   SYNOPSIS
  1075. *    error = MWLMeshMaterialNameGet( meshhandle,materialhandle,name )
  1076. *                                    D1         D2             D3
  1077. *
  1078. *    ULONG MWLMeshMaterialNameGet
  1079. *         ( ULONG,ULONG,STRPTR * );
  1080. *
  1081. *   FUNCTION
  1082. *    You will get a pointer to the name of the material. This string is READ_ONLY
  1083. *    and only valid as long as the mesh exists.
  1084. *   INPUTS
  1085. *     meshhandle     - A valid handle of a mesh.
  1086. *    materialhandle - A valid handle of a material.
  1087. *    name           - Pointer to the name of the material.
  1088. *    
  1089. *   RESULT
  1090. *     error - RCNOERROR    if all went well.
  1091. *            RCNOMESH     if the handle is not valid.
  1092. *            RCNOMATERIAL if the handle is not valid.
  1093. *   EXAMPLE
  1094. *    error = MWLMeshMaterialNameGet(meshhandle,materialhandle,&mystring);
  1095. *
  1096. *   NOTES
  1097. *
  1098. *   BUGS
  1099. *   SEE ALSO
  1100. *     MWLMeshMaterialNameSet()
  1101. ******************************************************************************
  1102. *
  1103. */
  1104. ULONG __saveds ASM MWLMeshMaterialNameGet(register __d1 ULONG meshhandle,
  1105.                                                 register __d2 ULONG materialhandle,
  1106.                                                 register __d3 STRPTR *name) {
  1107.     TOCLMesh            *mesh=NULL;
  1108.     TOCLMaterialNode    *mat=NULL;
  1109.     
  1110.     mesh=(TOCLMesh *) meshhandle;
  1111.     if(mesh==NULL) return(RCNOMESH);
  1112.  
  1113.     mat=getMaterialNode(mesh,materialhandle);
  1114.     if(mat==NULL) return(RCNOMATERIAL);
  1115.  
  1116.     (*name)=mat->name;
  1117.     
  1118.     return(RCNOERROR);
  1119. }
  1120.  
  1121. /****** meshwriter.library/MWLMeshMaterialAmbientColorSet ******************************************
  1122. *   NAME    
  1123. *     MWLMeshMaterialAmbientColorSet -- Set the ambient color of a material.
  1124. *   SYNOPSIS
  1125. *    error = MWLMeshMaterialAmbientColorSet( meshhandle,materialhandle,color )
  1126. *                                            D1         D2              A0
  1127. *
  1128. *    ULONG MWLMeshMaterialAmbientColorSet
  1129. *         ( ULONG,ULONG,TOCLColor * );
  1130. *
  1131. *   FUNCTION
  1132. *    The ambient color of the material will be set to the values passed by the
  1133. *    color structure.
  1134. *   INPUTS
  1135. *     meshhandle      - A valid handle of a mesh.
  1136. *    materialhandle  - A valid handle of a material.
  1137. *    color           - Pointer to a color structure containing the color information.
  1138. *    
  1139. *   RESULT
  1140. *     error - RCNOERROR    if all went well.
  1141. *            RCNOMESH     if the handle is not valid.
  1142. *            RCNOMATERIAL if the handle is not valid.
  1143. *
  1144. *   EXAMPLE
  1145. *    error = MWLMeshMaterialAmbientColorSet(meshhandle,materialhandle,&mycolor);
  1146. *
  1147. *   NOTES
  1148. *
  1149. *   BUGS
  1150. *   SEE ALSO
  1151. *     MWLMeshMaterialAmbientColorGet()
  1152. ******************************************************************************
  1153. *
  1154. */
  1155. ULONG __saveds ASM MWLMeshMaterialAmbientColorSet(register __d1 ULONG meshhandle,
  1156.                                                         register __d2 ULONG materialhandle,
  1157.                                                         register __a0 TOCLColor *color) {
  1158.     TOCLMesh            *mesh=NULL;
  1159.     TOCLMaterialNode    *mat=NULL;
  1160.     TOCLColor            *mcolor=NULL;
  1161.  
  1162.     // make a copy of color, because a0 is a scratch register
  1163.     mcolor = color;
  1164.     
  1165.     mesh=(TOCLMesh *) meshhandle;
  1166.     if(mesh==NULL) return(RCNOMESH);
  1167.   
  1168.     mat=getMaterialNode(mesh,materialhandle);
  1169.     if(mat==NULL) return(RCNOMATERIAL);
  1170.   
  1171.     mat->ambientColor=(*mcolor);
  1172.     
  1173.     return(RCNOERROR);
  1174. }
  1175.  
  1176. /****** meshwriter.library/MWLMeshMaterialAmbientColorGet ******************************************
  1177. *   NAME    
  1178. *     MWLMeshMaterialAmbientColorGet -- Get the ambient color of a material.
  1179. *   SYNOPSIS
  1180. *    error = MWLMeshMaterialAmbientColorGet( meshhandle,materialhandle,color )
  1181. *                                            D1         D2              A0
  1182. *
  1183. *    ULONG MWLMeshMaterialAmbientColorGet
  1184. *         ( ULONG,ULONG,TOCLColor * );
  1185. *
  1186. *   FUNCTION
  1187. *    The ambient color of the material will be written in the passed color structure.
  1188. *   INPUTS
  1189. *     meshhandle      - A valid handle of a mesh.
  1190. *    materialhandle  - A valid handle of a material.
  1191. *    color           - Pointer to a color structure which will contain
  1192. *                      the color information.
  1193. *    
  1194. *   RESULT
  1195. *     error - RCNOERROR    if all went well.
  1196. *            RCNOMESH     if the handle is not valid.
  1197. *            RCNOMATERIAL if the handle is not valid.
  1198. *
  1199. *   EXAMPLE
  1200. *    error = MWLMeshMaterialAmbientColorGet(meshhandle,materialhandle,&mycolor);
  1201. *
  1202. *   NOTES
  1203. *
  1204. *   BUGS
  1205. *   SEE ALSO
  1206. *     MWLMeshMaterialAmbientColorSet()
  1207. ******************************************************************************
  1208. *
  1209. */
  1210. ULONG __saveds ASM MWLMeshMaterialAmbientColorGet(register __d1 ULONG meshhandle,
  1211.                                                         register __d2 ULONG materialhandle,
  1212.                                                         register __a0 TOCLColor *color) {
  1213.     TOCLMesh            *mesh=NULL;
  1214.     TOCLMaterialNode    *mat=NULL;
  1215.     TOCLColor            *mcolor=NULL;
  1216.     
  1217.     // make a copy of color, a0 is a scratch register
  1218.     mcolor=color;
  1219.     
  1220.     mesh=(TOCLMesh *) meshhandle;
  1221.     if(mesh==NULL) return(RCNOMESH);
  1222.   
  1223.     mat=getMaterialNode(mesh,materialhandle);
  1224.     if(mat==NULL) return(RCNOMATERIAL);
  1225.   
  1226.     (*mcolor)=mat->ambientColor;
  1227.     
  1228.     return(RCNOERROR);
  1229. }
  1230.  
  1231. /****** meshwriter.library/MWLMeshMaterialShininessSet ******************************************
  1232. *   NAME    
  1233. *     MWLMeshMaterialShininessSet -- Set the shininess of a material.
  1234. *   SYNOPSIS
  1235. *    error = MWLMeshMaterialShininessSet( meshhandle,materialhandle,shininess )
  1236. *                                         D1         D2             D3
  1237. *
  1238. *    ULONG MWLMeshMaterialShininessSet
  1239. *         ( ULONG,ULONG,TOCLFloat );
  1240. *
  1241. *   FUNCTION
  1242. *    The shininess of the material will be set to the value passed by
  1243. *    shininess.
  1244. *   INPUTS
  1245. *     meshhandle      - A valid handle of a mesh.
  1246. *    materialhandle  - A valid handle of a material.
  1247. *    shininess       - Value of the shininess between 0.0 and 1.0.
  1248. *    
  1249. *   RESULT
  1250. *     error - RCNOERROR         if all went well.
  1251. *            RCNOMESH          if the handle is not valid.
  1252. *            RCNOMATERIAL      if the handle is not valid.
  1253. *            RCVALUEOUTOFRANGE if the value is out of range.
  1254. *
  1255. *   EXAMPLE
  1256. *    error = MWLMeshMaterialShininessSet(meshhandle,materialhandle,0.34);
  1257. *
  1258. *   NOTES
  1259. *
  1260. *   BUGS
  1261. *   SEE ALSO
  1262. *     MWLMeshMaterialShininessGet()
  1263. ******************************************************************************
  1264. *
  1265. */
  1266. ULONG __saveds ASM MWLMeshMaterialShininessSet(register __d1 ULONG meshhandle,
  1267.                                                     register __d2 ULONG materialhandle,
  1268.                                                     register __d3 TOCLFloat shininess) {
  1269.     TOCLMesh            *mesh=NULL;
  1270.     TOCLMaterialNode    *mat=NULL;
  1271.   
  1272.     mesh=(TOCLMesh *) meshhandle;
  1273.     if(mesh==NULL) return(RCNOMESH);
  1274.  
  1275.     mat=getMaterialNode(mesh,materialhandle);
  1276.     if(mat==NULL) return(RCNOMATERIAL);
  1277.     
  1278.     if(shininess>=0 && shininess <=1) mat->shininess=shininess;
  1279.     else return(RCVALUEOUTOFRANGE);
  1280.     
  1281.     return(RCNOERROR);
  1282. }
  1283.  
  1284. /****** meshwriter.library/MWLMeshMaterialShininessGet ******************************************
  1285. *   NAME    
  1286. *     MWLMeshMaterialShininessGet -- Get the shininess of a material.
  1287. *   SYNOPSIS
  1288. *    error = MWLMeshMaterialShininessGet( meshhandle,materialhandle,shininess )
  1289. *                                         D1         D2             D3
  1290. *
  1291. *    ULONG MWLMeshMaterialShininessGet
  1292. *         ( ULONG,ULONG,TOCLFloat * );
  1293. *
  1294. *   FUNCTION
  1295. *    The shininess of the material will be put into the variable pointed by shininess.
  1296. *   INPUTS
  1297. *     meshhandle      - A valid handle of a mesh.
  1298. *    materialhandle  - A valid handle of a material.
  1299. *    shininess       - Pointer to the variable which will contain the shininess.
  1300. *    
  1301. *   RESULT
  1302. *     error - RCNOERROR         if all went well.
  1303. *            RCNOMESH          if the handle is not valid.
  1304. *            RCNOMATERIAL      if the handle is not valid.
  1305. *
  1306. *   EXAMPLE
  1307. *    error = MWLMeshMaterialShininessGet(meshhandle,materialhandle,&myfloat);
  1308. *
  1309. *   NOTES
  1310. *
  1311. *   BUGS
  1312. *   SEE ALSO
  1313. *     MWLMeshMaterialShininessSet()
  1314. ******************************************************************************
  1315. *
  1316. */
  1317. ULONG __saveds ASM MWLMeshMaterialShininessGet(register __d1 ULONG meshhandle,
  1318.                                                     register __d2 ULONG materialhandle,
  1319.                                                     register __d3 TOCLFloat *shininess) {
  1320.     TOCLMesh            *mesh=NULL;
  1321.     TOCLMaterialNode    *mat=NULL;
  1322.   
  1323.     mesh=(TOCLMesh *) meshhandle;
  1324.     if(mesh==NULL) return(RCNOMESH);
  1325.  
  1326.     mat=getMaterialNode(mesh,materialhandle);
  1327.     if(mat==NULL) return(RCNOMATERIAL);
  1328.     
  1329.     (*shininess)=mat->shininess;
  1330.     
  1331.     return(RCNOERROR);
  1332. }
  1333.  
  1334. /****** meshwriter.library/MWLMeshMaterialTransparencySet ******************************************
  1335. *   NAME    
  1336. *     MWLMeshMaterialTransparencySet -- Set the transparency of a material.
  1337. *   SYNOPSIS
  1338. *    error = MWLMeshMaterialTransparencySet( meshhandle,materialhandle,transparency )
  1339. *                                            D1         D2             D3
  1340. *
  1341. *    ULONG MWLMeshMaterialTransparencySet
  1342. *         ( ULONG,ULONG,TOCLFloat );
  1343. *
  1344. *   FUNCTION
  1345. *    The transparency of the material will be set to the value passed by
  1346. *    transparency.
  1347. *   INPUTS
  1348. *     meshhandle      - A valid handle of a mesh.
  1349. *    materialhandle  - A valid handle of a material.
  1350. *    transparency    - Value of the transparency between 0.0 and 1.0.
  1351. *    
  1352. *   RESULT
  1353. *     error - RCNOERROR         if all went well.
  1354. *            RCNOMESH          if the handle is not valid.
  1355. *            RCNOMATERIAL      if the handle is not valid.
  1356. *            RCVALUEOUTOFRANGE if the value is out of range.
  1357. *
  1358. *   EXAMPLE
  1359. *    error = MWLMeshMaterialTransparencySet(meshhandle,materialhandle,0.9);
  1360. *
  1361. *   NOTES
  1362. *
  1363. *   BUGS
  1364. *   SEE ALSO
  1365. *     MWLMeshMaterialTransparencyGet()
  1366. ******************************************************************************
  1367. *
  1368. */
  1369. ULONG __saveds ASM MWLMeshMaterialTransparencySet(register __d1 ULONG meshhandle,
  1370.                                                         register __d2 ULONG materialhandle,
  1371.                                                         register __d3 TOCLFloat transparency) {
  1372.     TOCLMesh            *mesh=NULL;
  1373.     TOCLMaterialNode    *mat=NULL;
  1374.   
  1375.     mesh=(TOCLMesh *) meshhandle;
  1376.     if(mesh==NULL) return(RCNOMESH);
  1377.     
  1378.     mat=getMaterialNode(mesh,materialhandle);
  1379.     if(mat==NULL) return(RCNOMATERIAL);
  1380.     
  1381.     if(transparency>=0 && transparency<=1) mat->transparency=transparency;
  1382.     else return(RCVALUEOUTOFRANGE);
  1383.     
  1384.     return(RCNOERROR);
  1385. }
  1386.  
  1387. /****** meshwriter.library/MWLMeshMaterialTransparencyGet ******************************************
  1388. *   NAME    
  1389. *     MWLMeshMaterialTransparencyGet -- Get the transparency of a material.
  1390. *   SYNOPSIS
  1391. *    error = MWLMeshMaterialTransparencyGet( meshhandle,materialhandle,transparency )
  1392. *                                            D1         D2             D3
  1393. *
  1394. *    ULONG MWLMeshMaterialTransparencyGet
  1395. *         ( ULONG,ULONG,TOCLFloat * );
  1396. *
  1397. *   FUNCTION
  1398. *    The transparency of the material will be put into the variable pointed by transparency.
  1399. *   INPUTS
  1400. *     meshhandle      - A valid handle of a mesh.
  1401. *    materialhandle  - A valid handle of a material.
  1402. *    transparency    - Pointer to the variable which will contain the transparency.
  1403. *    
  1404. *   RESULT
  1405. *     error - RCNOERROR         if all went well.
  1406. *            RCNOMESH          if the handle is not valid.
  1407. *            RCNOMATERIAL      if the handle is not valid.
  1408. *
  1409. *   EXAMPLE
  1410. *    error = MWLMeshMaterialTransparencyGet(meshhandle,materialhandle,&myfloat);
  1411. *
  1412. *   NOTES
  1413. *
  1414. *   BUGS
  1415. *   SEE ALSO
  1416. *     MWLMeshMaterialTransparencySet()
  1417. ******************************************************************************
  1418. *
  1419. */
  1420. ULONG __saveds ASM MWLMeshMaterialTransparencyGet(register __d1 ULONG meshhandle,
  1421.                                                         register __d2 ULONG materialhandle,
  1422.                                                         register __d3 TOCLFloat *transparency) {
  1423.     TOCLMesh            *mesh=NULL;
  1424.     TOCLMaterialNode    *mat=NULL;
  1425.   
  1426.     mesh=(TOCLMesh *) meshhandle;
  1427.     if(mesh==NULL) return(RCNOMESH);
  1428.     
  1429.     mat=getMaterialNode(mesh,materialhandle);
  1430.     if(mat==NULL) return(RCNOMATERIAL);
  1431.     
  1432.     (*transparency)=mat->transparency;
  1433.     
  1434.     return(RCNOERROR);
  1435. }
  1436.  
  1437. /****** meshwriter.library/MWLMeshPolygonAdd ******************************************
  1438. *   NAME    
  1439. *     MWLMeshPolygonAdd -- Add a new polygon to the mesh.
  1440. *
  1441. *   SYNOPSIS
  1442. *    error = MWLMeshPolygonAdd( meshhandle,materialhandle )
  1443. *                               D1         D2
  1444. *
  1445. *    ULONG MWLMeshPolygonAdd
  1446. *         ( ULONG,ULONG );
  1447. *
  1448. *   FUNCTION
  1449. *    A new polygon will be created and added to the mesh.
  1450. *    With MWLMeshPolygonVertexAdd you can add vertices to this polygon.
  1451. *   INPUTS
  1452. *     meshhandle     - A valid handle of a mesh.
  1453. *    materialhandle - A valid handle of a material or 0 if you wont
  1454. *                     assign a material to this polygon now.
  1455. *    
  1456. *   RESULT
  1457. *     error - RCNOERROR    if all went well.
  1458. *            RCNOMESH     if the handle is not valid.
  1459. *            RCNOMATERIAL if the handle is not valid.
  1460. *            RCNOMEMORY   if there is not enough memory. 
  1461. *   EXAMPLE
  1462. *    error = MWLMeshPolygonAdd(meshhandle,materialhandle);
  1463. *
  1464. *   NOTES
  1465. *    Only convex polygons are supported.
  1466. *
  1467. *        Correct              Incorrect
  1468. *
  1469. *        *-----*              *----*
  1470. *       / \   /                \  /
  1471. *      /   \ /                  \/
  1472. *     / __--*                   /\
  1473. *    *--                       /  \
  1474. *                             *----*
  1475. *
  1476. *   BUGS
  1477. *   SEE ALSO
  1478. *     MWLMeshPolygonMaterialSet(),MWLMeshPolygonVertexAdd()
  1479. ******************************************************************************
  1480. *
  1481. */
  1482. ULONG __saveds ASM MWLMeshPolygonAdd(register __d1 ULONG meshhandle,
  1483.                                         register __d2 ULONG materialhandle) {
  1484.     TOCLMesh            *mesh=NULL;
  1485.     TOCLMaterialNode    *mat=NULL;
  1486.     TOCLPolygonNode    *pln=NULL;
  1487.         
  1488.     mesh=(TOCLMesh *) meshhandle;
  1489.     if (mesh==NULL) return(RCNOMESH);
  1490.  
  1491.     mat=getMaterialNode(mesh,materialhandle);
  1492.     if(materialhandle!=0 && mat==NULL) return(RCNOMATERIAL);
  1493.  
  1494.     /*
  1495.     ** Creat a new polygon, add it to the internal list
  1496.     */
  1497.     pln = AllocPooled(mesh->polygonpool,sizeof(TOCLPolygonNode));
  1498.     if (pln==NULL) return(RCNOMEMORY);
  1499.         
  1500.     pln->numberOfVertices=0;
  1501.     pln->firstNode=NULL;
  1502.     pln->lastNode=NULL;
  1503.     pln->next=NULL;
  1504.     pln->materialNode=mat;
  1505.         
  1506.     if(mesh->polygons.firstNode!=NULL) {   /* Check if this is the first polygon to insert or not */
  1507.         mesh->polygons.lastNode->next=pln;
  1508.         mesh->polygons.lastNode=pln;
  1509.     }
  1510.     else {
  1511.         mesh->polygons.lastNode=pln;
  1512.         mesh->polygons.firstNode=pln;
  1513.     }
  1514.  
  1515.     /*
  1516.     ** Increment the polygon counter
  1517.     */
  1518.     mesh->polygons.numberOfPolygons++;
  1519.         
  1520.     return(RCNOERROR);
  1521. }
  1522.  
  1523. /****** meshwriter.library/MWLMeshPolygonMaterialSet ******************************************
  1524. *   NAME    
  1525. *     MWLMeshPolygonMaterialSet -- Set the material of the most recent polygon.
  1526. *   SYNOPSIS
  1527. *    error = MWLMeshPolygonMaterialSet( meshhandle,materialhandle )
  1528. *                                       D1         D2
  1529. *
  1530. *    ULONG MWLMeshPolygonMaterialSet
  1531. *         ( ULONG,ULONG );
  1532. *
  1533. *   FUNCTION
  1534. *    The material of the most recent polygon will be set to the one you
  1535. *    pass by the handle.
  1536. *   INPUTS
  1537. *     meshhandle      - A valid handle of a mesh.
  1538. *    materialhandle  - A valid handle of a material.
  1539. *    
  1540. *   RESULT
  1541. *     error - RCNOERROR    if all went well.
  1542. *            RCNOMESH     if the handle is not valid.
  1543. *            RCNOMATERIAL if the handle is not valid.
  1544. *            RCNOPOLYGON  if there is no polygon to work with.     
  1545. *
  1546. *   EXAMPLE
  1547. *    error = MWLMeshPolygonMaterialSet(meshhandle,materialhandle);
  1548. *
  1549. *   NOTES
  1550. *    As all is a polygon, after calling MWLMeshTriangleAdd() with this
  1551. *    function you can set the material of the new triangle too.
  1552. *
  1553. *   BUGS
  1554. *   SEE ALSO
  1555. *     MWLMeshPolygonAdd(),MWLMeshTriangleAdd()
  1556. ******************************************************************************
  1557. *
  1558. */
  1559. ULONG __saveds ASM MWLMeshPolygonMaterialSet(register __d1 ULONG meshhandle,
  1560.                                                 register __d2 ULONG materialhandle) {
  1561.     TOCLMesh            *mesh=NULL;
  1562.     TOCLMaterialNode    *mat=NULL;
  1563.         
  1564.     mesh=(TOCLMesh *) meshhandle;
  1565.     if(mesh==NULL) return(RCNOMESH);
  1566.  
  1567.    if(mesh->polygons.lastNode==NULL) return(RCNOPOLYGON); /* There is no polygon to work with */
  1568.  
  1569.     /*
  1570.     ** Set the material to this polygon
  1571.     */
  1572.     mat=getMaterialNode(mesh,materialhandle);
  1573.     if(materialhandle!=0 && mat==NULL) return(RCNOMATERIAL);
  1574.     
  1575.     mesh->polygons.lastNode->materialNode=mat;
  1576.  
  1577.     return(RCNOERROR);
  1578. }
  1579.  
  1580. /****** meshwriter.library/MWLMeshPolygonVertexAdd ******************************************
  1581. *   NAME    
  1582. *     MWLMeshPolygonVertexAdd -- Add a new vertex to the most recent polygon,
  1583. *                               according the CTM.
  1584. *
  1585. *   SYNOPSIS
  1586. *    error = MWLMeshPolygonVertexAdd( meshhandle,vertex )
  1587. *                                     D1          A0
  1588. *
  1589. *    ULONG MWLMeshPolygonAdd
  1590. *         ( ULONG,TOCLVertex * );
  1591. *
  1592. *   FUNCTION
  1593. *    A new vertex will be added to the polygon. A copy of the contents passed
  1594. *    by the vertex pointer will be made.
  1595. *   INPUTS
  1596. *     meshhandle   - A valid handle of a mesh.
  1597. *    vertex       - Pointer to a vertex structure which contains the coordinates
  1598. *                   of the new vertex.
  1599. *    
  1600. *   RESULT
  1601. *     error - RCNOERROR    if all went well.
  1602. *            RCNOMESH     if the handle is not valid.
  1603. *            RCNOMEMORY   if there is not enough memory. 
  1604. *            RCNOPOLYGON  if there is no polygon to work with.
  1605. *   EXAMPLE
  1606. *    error = MWLMeshPolygonVertexAdd(meshhandle,&myvertex);
  1607. *
  1608. *   NOTES
  1609. *    Vertices have to be added in counterclock wise direction.
  1610. *
  1611. *          v3
  1612. *         / |
  1613. *        /  |
  1614. *       /   |
  1615. *      /    |
  1616. *     /     |
  1617. *    v1--->v2
  1618. *
  1619. *
  1620. *   BUGS
  1621. *   SEE ALSO
  1622. *     MWLMeshPolygonAdd()
  1623. ******************************************************************************
  1624. *
  1625. */
  1626. ULONG __saveds ASM MWLMeshPolygonVertexAdd(register __d1 ULONG meshhandle,
  1627.                                                 register __a0 TOCLVertex *vertex) {
  1628.                                 
  1629.     TOCLMesh                    *mesh=NULL;
  1630.     TOCLVertexNode                *ver=NULL;
  1631.     TOCLPolygonsVerticesNode    *plv=NULL;
  1632.     TOCLPolygonNode            *pln=NULL;
  1633.     TOCLVertex                    *mvertex=NULL;
  1634.       
  1635.     // make a copy of vertex, a0 is a scratch register
  1636.     mvertex=vertex;
  1637.     
  1638.     mesh=(TOCLMesh *) meshhandle;
  1639.     if (mesh==NULL) return(RCNOMESH);
  1640.  
  1641.     if(mesh->polygons.lastNode==NULL) return(RCNOPOLYGON); /* There is no polygon to work with */
  1642.  
  1643.     /*
  1644.     ** Add a new vertice to the internal vertice list
  1645.     */
  1646.     ver = addVertex(mesh,(*mvertex));
  1647.     if (ver==NULL) {
  1648.         return(RCNOMEMORY);
  1649.     }
  1650.     
  1651.     /*
  1652.     ** Add a new polygon vertex node to the polygon list its last element
  1653.     */
  1654.     plv = AllocPooled(mesh->polygonverticespool,sizeof(TOCLPolygonsVerticesNode));
  1655.     if (plv==NULL) {
  1656.         return(RCNOMEMORY);
  1657.     }
  1658.         
  1659.     plv->vertexNode=ver;
  1660.     plv->next=NULL;
  1661.  
  1662.     pln=mesh->polygons.lastNode;
  1663.      
  1664.     if(pln->firstNode!=NULL) {   /* Check if this is the first vertex to insert or not */
  1665.         pln->lastNode->next=plv;
  1666.         pln->lastNode=plv;
  1667.     }
  1668.     else {
  1669.         pln->lastNode=plv;
  1670.         pln->firstNode=plv;
  1671.     }
  1672.     
  1673.     /*
  1674.     ** Increment the number of vertices counter of the polygon
  1675.     */
  1676.     pln->numberOfVertices++;
  1677.         
  1678.     return(RCNOERROR);
  1679. }
  1680.  
  1681. /****** meshwriter.library/MWLMeshTriangleAdd ******************************************
  1682. *   NAME    
  1683. *     MWLMeshTriangleAdd -- Add a new triangle to the mesh according the CTM.
  1684. *
  1685. *   SYNOPSIS
  1686. *    error = MWLMeshTriangleAdd( meshhandle,materialhandle,vertex1,vertex2,vertex3 )
  1687. *                                D1         D2              A0       A1      A2
  1688. *
  1689. *    ULONG MWLMeshTriangleAdd
  1690. *         ( ULONG,ULONG,TOCLVertex *,TOCLVertex *,TOCLVertex * );
  1691. *
  1692. *   FUNCTION
  1693. *    A new triangle will be added to the mesh.
  1694. *    This means a new polygon with 3 vertices.
  1695. *    A copy of the contents passed by the vertex pointers will be made.
  1696. *   INPUTS
  1697. *     meshhandle     - A valid handle of a mesh.
  1698. *    materialhandle - A valid handle of a material or 0 if you wont
  1699. *                     assign a material to this polygon now.
  1700. *    vertex1        - Pointer to the first vertex structure.
  1701. *    vertex2        - Pointer to the second vertex structure.
  1702. *    vertex3        - Pointer to the third vertex structure.
  1703. *    
  1704. *   RESULT
  1705. *     error - RCNOERROR    if all went well.
  1706. *            RCNOMESH     if the handle is not valid.
  1707. *            RCNOMATERIAL if the handle is not valid.
  1708. *            RCNOMEMORY   if there is not enough memory. 
  1709. *   EXAMPLE
  1710. *    error = MWLMeshTriangleAdd(meshhandle,materialhandle,&v1,&v2,&v3);
  1711. *
  1712. *   NOTES
  1713. *    Vertices have to be added in counterclock wise direction.
  1714. *
  1715. *          v3
  1716. *         / |
  1717. *        /  |
  1718. *       /   |
  1719. *      /    |
  1720. *     /     |
  1721. *    v1--->v2
  1722. *
  1723. *   BUGS
  1724. *   SEE ALSO
  1725. *     MWLMeshPolygonMaterialSet()
  1726. ******************************************************************************
  1727. *
  1728. */
  1729. ULONG __saveds ASM MWLMeshTriangleAdd(register __d1 ULONG meshhandle,
  1730.                                         register __d2 ULONG materialhandle,
  1731.                                         register __a0 TOCLVertex *vertex1,
  1732.                                         register __a1 TOCLVertex *vertex2,
  1733.                                         register __a2 TOCLVertex *vertex3) {
  1734.  
  1735.     TOCLMesh                    *mesh=NULL;
  1736.     TOCLMaterialNode            *mat=NULL;
  1737.     TOCLPolygonNode            *pln=NULL;
  1738.     TOCLVertexNode                *ver1=NULL,*ver2=NULL,*ver3=NULL;
  1739.     TOCLPolygonsVerticesNode    *plv1=NULL,*plv2=NULL;
  1740.     TOCLVertex                    *mvertex1=NULL,*mvertex2=NULL,*mvertex3=NULL;
  1741.     
  1742.     // make a copy of vertex1 to 3, a0 and a1 are a scratch registers
  1743.     mvertex1=vertex1;
  1744.     mvertex2=vertex2;
  1745.     mvertex3=vertex3;
  1746.  
  1747.     mesh=(TOCLMesh *) meshhandle;
  1748.     if (mesh==NULL) return(RCNOMESH);
  1749.  
  1750.     mat=getMaterialNode(mesh,materialhandle);
  1751.     if(materialhandle!=0 && mat==NULL) return(RCNOMATERIAL);
  1752.  
  1753.     /*
  1754.     ** Create a new polygon, add it to the internal list
  1755.     */
  1756.     pln = AllocPooled(mesh->polygonpool,sizeof(TOCLPolygonNode));
  1757.     if (pln==NULL) {
  1758.         return(RCNOMEMORY);
  1759.     }
  1760.         
  1761.     pln->numberOfVertices=0;
  1762.     pln->firstNode=NULL;
  1763.     pln->lastNode=NULL;
  1764.     pln->next=NULL;
  1765.     pln->materialNode=mat;
  1766.         
  1767.     if(mesh->polygons.firstNode!=NULL) {   /* Check if this is the first polygon to insert or not */
  1768.         mesh->polygons.lastNode->next=pln;
  1769.         mesh->polygons.lastNode=pln;
  1770.     }
  1771.     else {
  1772.         mesh->polygons.lastNode=pln;
  1773.         mesh->polygons.firstNode=pln;
  1774.     }
  1775.  
  1776.     /*
  1777.     ** Increment the polygon counter
  1778.     */
  1779.     mesh->polygons.numberOfPolygons++;
  1780.  
  1781.     /*
  1782.     ** Add the 3 new vertices to the internal vertice list,
  1783.     ** and add the number of vertices counter of the polygon
  1784.     */
  1785.     ver1 = addVertex(mesh,(*mvertex1));
  1786.     if (ver1==NULL) return(RCNOMEMORY);
  1787.     pln->numberOfVertices++;
  1788.     ver2 = addVertex(mesh,(*mvertex2));
  1789.     if (ver2==NULL) return(RCNOMEMORY);
  1790.     pln->numberOfVertices++;
  1791.     ver3 = addVertex(mesh,(*mvertex3));
  1792.     if (ver3==NULL) return(RCNOMEMORY);
  1793.     pln->numberOfVertices++;
  1794.  
  1795.     /*
  1796.     ** Add the 3 new polygon vertices node to the polygon list its last element
  1797.     */
  1798.     plv1 = AllocPooled(mesh->polygonverticespool,sizeof(TOCLPolygonsVerticesNode));
  1799.     if (plv1==NULL) return(RCNOMEMORY);
  1800.     
  1801.     plv1->vertexNode=ver3;
  1802.     plv1->next=NULL;
  1803.  
  1804.     plv2 = AllocPooled(mesh->polygonverticespool,sizeof(TOCLPolygonsVerticesNode));
  1805.     if (plv2==NULL) return(RCNOMEMORY);
  1806.     
  1807.     plv2->vertexNode=ver2;
  1808.     plv2->next=plv1;
  1809.  
  1810.     plv1 = AllocPooled(mesh->polygonverticespool,sizeof(TOCLPolygonsVerticesNode));
  1811.     if (plv1==NULL) return(RCNOMEMORY);        
  1812.     
  1813.     plv1->vertexNode=ver1;
  1814.     plv1->next=plv2;
  1815.  
  1816.  
  1817.     pln=mesh->polygons.lastNode;
  1818.      
  1819.     if(pln->firstNode!=NULL) {   /* Check if this is the first vertex to insert or not */
  1820.         pln->lastNode->next=plv1;
  1821.         pln->lastNode=plv1;
  1822.     }
  1823.     else {
  1824.         pln->lastNode=plv1;
  1825.         pln->firstNode=plv1;
  1826.     }
  1827.     
  1828.     return(RCNOERROR);
  1829. }
  1830.  
  1831. /****** meshwriter.library/MWLMeshNumberOfMaterialsGet ******************************************
  1832. *   NAME    
  1833. *     MWLMeshNumberOfMaterialsGet -- Get the number of materials in a mesh.
  1834. *   SYNOPSIS
  1835. *    number = MWLMeshNumberOfMaterialsGet( meshhandle )
  1836. *                                          D1
  1837. *
  1838. *    ULONG MWLMeshNumberOfMaterialsGet
  1839. *         ( ULONG )
  1840. *
  1841. *   FUNCTION
  1842. *    The current number of materials found in the mesh will be returned.
  1843. *   INPUTS
  1844. *     meshhandle      - A valid handle of a mesh.
  1845. *    
  1846. *   RESULT
  1847. *     number - Number of materials, 0 if any or no valid mesh.
  1848. *
  1849. *   EXAMPLE
  1850. *    number = MWLMeshNumberOfMaterialsGet(meshhandle);
  1851. *
  1852. *   NOTES
  1853. *
  1854. *   BUGS
  1855. *   SEE ALSO
  1856. *     MWLMeshNumberOfPolygonsGet(),MWLMeshNumberOfVerticesGet()
  1857. ******************************************************************************
  1858. *
  1859. */
  1860. ULONG __saveds ASM MWLMeshNumberOfMaterialsGet(register __d1 ULONG meshhandle) {
  1861.     TOCLMesh *mesh=NULL;
  1862.     
  1863.     mesh = (TOCLMesh *) meshhandle;
  1864.     if(mesh==NULL) return(0);
  1865.     
  1866.     return(mesh->materials.numberOfMaterials);
  1867. }
  1868.  
  1869. /****** meshwriter.library/MWLMeshNumberOfPolygonsGet ******************************************
  1870. *   NAME    
  1871. *     MWLMeshNumberOfPolygonsGet -- Get the number of polygons in a mesh.
  1872. *   SYNOPSIS
  1873. *    number = MWLMeshNumberOfPolygonsGet( meshhandle )
  1874. *                                         D1
  1875. *
  1876. *    ULONG MWLMeshNumberOfPolygonsGet
  1877. *         ( ULONG )
  1878. *
  1879. *   FUNCTION
  1880. *    The current number of polygons found in the mesh will be returned.
  1881. *   INPUTS
  1882. *     meshhandle      - A valid handle of a mesh.
  1883. *    
  1884. *   RESULT
  1885. *     number - Number of polygons, 0 if any or no valid mesh.
  1886. *
  1887. *   EXAMPLE
  1888. *    number = MWLMeshNumberOfPolygonsGet(meshhandle);
  1889. *
  1890. *   NOTES
  1891. *
  1892. *   BUGS
  1893. *   SEE ALSO
  1894. *     MWLMeshNumberOfMaterialsGet(),MWLMeshNumberOfVerticesGet()
  1895. ******************************************************************************
  1896. *
  1897. */
  1898. ULONG __saveds ASM MWLMeshNumberOfPolygonsGet(register __d1 ULONG meshhandle) {
  1899.     TOCLMesh *mesh=NULL;
  1900.     
  1901.     mesh = (TOCLMesh *) meshhandle;
  1902.     if(mesh==NULL) return(0);
  1903.     
  1904.     return(mesh->polygons.numberOfPolygons);
  1905. }
  1906.  
  1907. /****** meshwriter.library/MWLMeshNumberOfVerticesGet ******************************************
  1908. *   NAME    
  1909. *     MWLMeshNumberOfVerticesGet -- Get the number of vertices in a mesh.
  1910. *   SYNOPSIS
  1911. *    number = MWLMeshNumberOfVerticesGet( meshhandle )
  1912. *                                         D1
  1913. *
  1914. *    ULONG MWLMeshNumberOfVerticesGet
  1915. *         ( ULONG )
  1916. *
  1917. *   FUNCTION
  1918. *    The current number of vertices found in the mesh will be returned.
  1919. *   INPUTS
  1920. *     meshhandle      - A valid handle of a mesh.
  1921. *    
  1922. *   RESULT
  1923. *     number - Number of vertices, 0 if any or no valid mesh.
  1924. *
  1925. *   EXAMPLE
  1926. *    number = MWLMeshNumberOfVerticesGet(meshhandle);
  1927. *
  1928. *   NOTES
  1929. *
  1930. *   BUGS
  1931. *   SEE ALSO
  1932. *     MWLMeshNumberOfMaterialsGet(),MWLMeshNumberOfPolygonsGet()
  1933. ******************************************************************************
  1934. *
  1935. */
  1936. ULONG __saveds ASM MWLMeshNumberOfVerticesGet(register __d1 ULONG meshhandle) {
  1937.     TOCLMesh *mesh=NULL;
  1938.     
  1939.     mesh = (TOCLMesh *) meshhandle;
  1940.     if(mesh==NULL) return(0);
  1941.     
  1942.     return(mesh->vertices.numberOfVertices);
  1943. }
  1944.  
  1945. /****** meshwriter.library/MWLMeshCameraLightDefaultSet ******************************************
  1946. *   NAME    
  1947. *     MWLMeshCameraLightDefaultSet -- Set the camera and light to defaults.
  1948. *   SYNOPSIS
  1949. *    error = MWLMeshCameraLightDefaultSet( meshhandle )
  1950. *                                          D1
  1951. *
  1952. *    ULONG MWLMeshCameraLightDefaultSet
  1953. *         ( ULONG )
  1954. *
  1955. *   FUNCTION
  1956. *    This function sets the camera and light properties as follows :
  1957. *    Camera looks to the center of the mesh and is positioned to view the whole mesh.
  1958. *    Light is positioned at the same point than the camera and gets a white color.
  1959. *   INPUTS
  1960. *     meshhandle      - A valid handle of a mesh.
  1961. *    
  1962. *   RESULT
  1963. *     error - RCNOERROR    if all went well.
  1964. *            RCNOMESH     if the handle is not valid.
  1965. *
  1966. *   EXAMPLE
  1967. *    error= MWLMeshCameraLightDefaultSet(meshhandle);
  1968. *
  1969. *   NOTES
  1970. *    Camera and light will be used by some file formats only,
  1971. *    and for 2D or display functions.
  1972. *
  1973. *    If no values are set, this function will be called internally before
  1974. *    using functions which need a camera or a light source.
  1975. *
  1976. *   BUGS
  1977. *   SEE ALSO
  1978. *     MWLMeshCameraPositionSet(),MWLMeshCameraLookAtSet(),
  1979. *    MWLMeshLightPositionSet(),MWLMeshLightColorSet()
  1980. ******************************************************************************
  1981. *
  1982. */
  1983. ULONG __saveds ASM MWLMeshCameraLightDefaultSet(register __d1 ULONG meshhandle) {
  1984.     TOCLMesh *mesh=NULL;
  1985.   
  1986.     mesh=(TOCLMesh *) meshhandle;
  1987.     if(mesh==NULL) return(RCNOMESH);
  1988.     
  1989.     setCameraLight(mesh);
  1990.     
  1991.     return(RCNOERROR);
  1992. }
  1993.  
  1994. /****** meshwriter.library/MWLMeshCameraPositionSet ******************************************
  1995. *   NAME    
  1996. *     MWLMeshCameraPositionSet -- Set the camera position.
  1997. *   SYNOPSIS
  1998. *    error = MWLMeshCameraPositionSet( meshhandle,position )
  1999. *                                      D1          A0
  2000. *
  2001. *    ULONG MWLMeshCameraPositionSet
  2002. *         ( ULONG,TOCLVertex * );
  2003. *
  2004. *   FUNCTION
  2005. *    The position of the camera will be set to the values passed by the
  2006. *    vertex structure.
  2007. *   INPUTS
  2008. *     meshhandle      - A valid handle of a mesh.
  2009. *    position        - Pointer to a vertex structure containing the position information.
  2010. *    
  2011. *   RESULT
  2012. *     error - RCNOERROR    if all went well.
  2013. *`            RCNOMESH     if the handle is not valid.
  2014. *
  2015. *   EXAMPLE
  2016. *    error = MWLMeshCameraPositionSet(meshhandle,&myvertex);
  2017. *
  2018. *   NOTES
  2019. *    The camera will be used by some file formats only,
  2020. *    and for 2D or display functions.
  2021. *
  2022. *   BUGS
  2023. *   SEE ALSO
  2024. *     MWLMeshCameraPositionGet(),MWLMeshCameraLookAtSet(),
  2025. *    MWLMeshCameraLookAtGet()
  2026. ******************************************************************************
  2027. *
  2028. */
  2029. ULONG __saveds ASM MWLMeshCameraPositionSet(register __d1 ULONG meshhandle,
  2030.                                                 register __a0 TOCLVertex *position) {
  2031.     TOCLMesh        *mesh=NULL;
  2032.     TOCLVertex        *mposition=NULL;
  2033.     
  2034.     // make a copy of position, a0 is a scratch register
  2035.     mposition=position;
  2036.   
  2037.     mesh=(TOCLMesh *) meshhandle;
  2038.     if(mesh==NULL) return(RCNOMESH);
  2039.     
  2040.     mesh->camera.position=(*mposition);
  2041.     
  2042.     return(RCNOERROR);
  2043. }
  2044.  
  2045. /****** meshwriter.library/MWLMeshCameraPositionGet ******************************************
  2046. *   NAME    
  2047. *     MWLMeshCameraPositionGet -- Get the position of the camera.
  2048. *   SYNOPSIS
  2049. *    error = MWLMeshCameraPositionGet( meshhandle,position )
  2050. *                                      D1          A0
  2051. *
  2052. *    ULONG MWLMeshCameraPositionGet
  2053. *         ( ULONG,TOCLVertex * );
  2054. *
  2055. *   FUNCTION
  2056. *    The position of the camera will be written in the passed vertex structure.
  2057. *   INPUTS
  2058. *     meshhandle      - A valid handle of a mesh.
  2059. *    position        - Pointer to a vertex structure which will contain
  2060. *                      the position information.
  2061. *    
  2062. *   RESULT
  2063. *     error - RCNOERROR    if all went well.
  2064. *            RCNOMESH     if the handle is not valid.
  2065. *
  2066. *   EXAMPLE
  2067. *    error = MWLMeshCameraPositionGet(meshhandle,&myvertex);
  2068. *
  2069. *   NOTES
  2070. *    The camera will be used by some file formats only,
  2071. *    and for 2D or display functions.
  2072. *
  2073. *   BUGS
  2074. *   SEE ALSO
  2075. *     MWLMeshCameraPositionSet(),MWLMeshCameraLookAtSet()
  2076. *    MWLMeshCameraLookAtGet()
  2077. ******************************************************************************
  2078. *
  2079. */
  2080. ULONG __saveds ASM MWLMeshCameraPositionGet(register __d1 ULONG meshhandle,
  2081.                                                 register __a0 TOCLVertex *position) {
  2082.     TOCLMesh        *mesh=NULL;
  2083.     TOCLVertex    *mposition=NULL;
  2084.     
  2085.     // make a copy of position, a0 is a scratch register
  2086.     mposition=position;
  2087.  
  2088.     mesh = (TOCLMesh *) meshhandle;
  2089.     if(mesh==NULL) return(RCNOMESH);
  2090.  
  2091.     (*mposition)=mesh->camera.position;
  2092.     
  2093.     return(RCNOERROR);
  2094. }
  2095.  
  2096. /****** meshwriter.library/MWLMeshCameraLookAtSet ******************************************
  2097. *   NAME    
  2098. *     MWLMeshCameraLookAtSet -- Set the camera its view point.
  2099. *   SYNOPSIS
  2100. *    error = MWLMeshCameraLookAtSet( meshhandle,lookat )
  2101. *                                    D1          A0
  2102. *
  2103. *    ULONG MWLMeshCameraLookAtSet
  2104. *         ( ULONG,TOCLVertex * );
  2105. *
  2106. *   FUNCTION
  2107. *    The view point of the camera will be set to the values passed by the
  2108. *    vertex structure.
  2109. *   INPUTS
  2110. *     meshhandle      - A valid handle of a mesh.
  2111. *    lookat          - Pointer to a vertex structure containing the position information.
  2112. *    
  2113. *   RESULT
  2114. *     error - RCNOERROR    if all went well.
  2115. *            RCNOMESH     if the handle is not valid.
  2116. *
  2117. *   EXAMPLE
  2118. *    error = MWLMeshCameraLookAtSet(meshhandle,&myvertex);
  2119. *
  2120. *   NOTES
  2121. *    The camera will be used by some file formats only,
  2122. *    and for 2D or display functions.
  2123. *
  2124. *   BUGS
  2125. *   SEE ALSO
  2126. *     MWLMeshCameraLookAtGet(),MWLMeshCameraPositionSet()
  2127. *    MWLMeshCameraPositionSet()
  2128. ******************************************************************************
  2129. *
  2130. */
  2131. ULONG __saveds ASM MWLMeshCameraLookAtSet(register __d1 ULONG meshhandle,
  2132.                                             register __a0 TOCLVertex *lookat) {
  2133.     TOCLMesh        *mesh=NULL;
  2134.     TOCLVertex        *mlookat=NULL;
  2135.  
  2136.     // make a copy of lookat, a0 is a scratch register
  2137.     mlookat=lookat;
  2138.  
  2139.     mesh=(TOCLMesh *) meshhandle;
  2140.     if(mesh==NULL) return(RCNOMESH);
  2141.     
  2142.     mesh->camera.lookat=(*mlookat);
  2143.     
  2144.     return(RCNOERROR);
  2145. }
  2146.  
  2147. /****** meshwriter.library/MWLMeshCameraLookAtGet ******************************************
  2148. *   NAME    
  2149. *     MWLMeshCameraLookAtGet -- Get the view point of the camera.
  2150. *   SYNOPSIS
  2151. *    error = MWLMeshCameraLookAtGet( meshhandle,lookat )
  2152. *                                    D1          A0
  2153. *
  2154. *    ULONG MWLMeshCameraLookAtGet
  2155. *         ( ULONG,TOCLVertex * );
  2156. *
  2157. *   FUNCTION
  2158. *    The view point of the camera will be written in the passed vertex structure.
  2159. *   INPUTS
  2160. *     meshhandle      - A valid handle of a mesh.
  2161. *    lookat          - Pointer to a vertex structure which will contain
  2162. *                      the position information.
  2163. *    
  2164. *   RESULT
  2165. *     error - RCNOERROR    if all went well.
  2166. *            RCNOMESH     if the handle is not valid.
  2167. *
  2168. *   EXAMPLE
  2169. *    error = MWLMeshCameraLookAtGet(meshhandle,&myvertex);
  2170. *
  2171. *   NOTES
  2172. *    The camera will be used by some file formats only,
  2173. *    and for 2D or display functions.
  2174. *
  2175. *   BUGS
  2176. *   SEE ALSO
  2177. *     MWLMeshCameraLookAtSet(),MWLMeshCameraPositionSet()
  2178. *    MWLMeshCameraPositionGet()
  2179. ******************************************************************************
  2180. *
  2181. */
  2182. ULONG __saveds ASM MWLMeshCameraLookAtGet(register __d1 ULONG meshhandle,
  2183.                                             register __a0 TOCLVertex *lookat) {
  2184.     TOCLMesh        *mesh=NULL;
  2185.     TOCLVertex        *mlookat=NULL;
  2186.     
  2187.     // make a copy of lookat, a0 is a scratch register
  2188.     mlookat=lookat;
  2189.   
  2190.     mesh=(TOCLMesh *) meshhandle;
  2191.     if(mesh==NULL) return(RCNOMESH);
  2192.  
  2193.     (*mlookat)=mesh->camera.lookat;
  2194.     
  2195.     return(RCNOERROR);
  2196. }
  2197.  
  2198. /****** meshwriter.library/MWLMeshLightPositionSet ******************************************
  2199. *   NAME    
  2200. *     MWLMeshLightPositionSet -- Set the light source its position.
  2201. *   SYNOPSIS
  2202. *    error = MWLMeshLightPositionSet( meshhandle,position )
  2203. *                                     D1          A0
  2204. *
  2205. *    ULONG MWLMeshLightPositionSet
  2206. *         ( ULONG,TOCLVertex * );
  2207. *
  2208. *   FUNCTION
  2209. *    The position of the light source will be set to the values passed by the
  2210. *    vertex structure.
  2211. *   INPUTS
  2212. *     meshhandle      - A valid handle of a mesh.
  2213. *    position        - Pointer to a vertex structure containing the position information.
  2214. *    
  2215. *   RESULT
  2216. *     error - RCNOERROR    if all went well.
  2217. *            RCNOMESH     if the handle is not valid.
  2218. *
  2219. *   EXAMPLE
  2220. *    error = MWLMeshLightPositionSet(meshhandle,&myvertex);
  2221. *
  2222. *   NOTES
  2223. *    The light will be used by some file formats only,
  2224. *    and for 2D or display functions.
  2225. *
  2226. *   BUGS
  2227. *   SEE ALSO
  2228. *     MWLMeshLightPositionGet(),MWLMeshLightColorSet()
  2229. *    MWLMeshLightColorGet()
  2230. ******************************************************************************
  2231. *
  2232. */
  2233. ULONG __saveds ASM MWLMeshLightPositionSet(register __d1 ULONG meshhandle,
  2234.                                                 register __a0 TOCLVertex *position) {
  2235.     TOCLMesh        *mesh=NULL;
  2236.     TOCLVertex        *mposition=NULL;
  2237.  
  2238.     // make a copy of position, a0 is a scratch register
  2239.     mposition=position;
  2240.  
  2241.     mesh=(TOCLMesh *) meshhandle;
  2242.     if(mesh==NULL) return(RCNOMESH);
  2243.     
  2244.     mesh->light.position=(*mposition);
  2245.     
  2246.     return(RCNOERROR);
  2247. }
  2248.  
  2249. /****** meshwriter.library/MWLMeshLightPositionGet ******************************************
  2250. *   NAME    
  2251. *     MWLMeshLightPositionGet -- Get the position of the light source.
  2252. *   SYNOPSIS
  2253. *    error = MWLMeshLightPositionGet( meshhandle,position )
  2254. *                                     D1          A0
  2255. *
  2256. *    ULONG MWLMeshLightPositionGet
  2257. *         ( ULONG,TOCLVertex * );
  2258. *
  2259. *   FUNCTION
  2260. *    The position of the light source will be written in the passed vertex structure.
  2261. *   INPUTS
  2262. *     meshhandle      - A valid handle of a mesh.
  2263. *    position        - Pointer to a vertex structure which will contain
  2264. *                      the position information.
  2265. *    
  2266. *   RESULT
  2267. *     error - RCNOERROR    if all went well.
  2268. *            RCNOMESH     if the handle is not valid.
  2269. *
  2270. *   EXAMPLE
  2271. *    error = MWLMeshLightPositionGet(meshhandle,&myvertex);
  2272. *
  2273. *   NOTES
  2274. *    The light will be used by some file formats only,
  2275. *    and for 2D or display functions.
  2276. *
  2277. *   BUGS
  2278. *   SEE ALSO
  2279. *     MWLMeshLightPositionSet(),MWLMeshLightColorSet()
  2280. *    MWLMeshLightColorGet()
  2281. ******************************************************************************
  2282. *
  2283. */
  2284. ULONG __saveds ASM MWLMeshLightPositionGet(register __d1 ULONG meshhandle,
  2285.                                                 register __a0 TOCLVertex *position) {
  2286.     TOCLMesh        *mesh=NULL;
  2287.     TOCLVertex        *mposition=NULL;
  2288.     
  2289.     // make a copy of position, a0 is a scratch register
  2290.     mposition=position;
  2291.   
  2292.     mesh=(TOCLMesh *) meshhandle;
  2293.     if(mesh==NULL) return(RCNOMESH);
  2294.  
  2295.     (*mposition)=mesh->light.position;
  2296.     
  2297.     return(RCNOERROR);
  2298. }
  2299.  
  2300. /****** meshwriter.library/MWLMeshLightColorSet ******************************************
  2301. *   NAME    
  2302. *     MWLMeshLightColorSet -- Set the light source its color.
  2303. *   SYNOPSIS
  2304. *    error = MWLMeshLightColorSet( meshhandle,color )
  2305. *                                  D1          A0
  2306. *
  2307. *    ULONG MWLMeshLightColorSet
  2308. *         ( ULONG,TOCLColor * );
  2309. *
  2310. *   FUNCTION
  2311. *    The color of the light source will be set to the values passed by the
  2312. *    color structure.
  2313. *   INPUTS
  2314. *     meshhandle      - A valid handle of a mesh.
  2315. *    color           - Pointer to a color structure containing the color information.
  2316. *    
  2317. *   RESULT
  2318. *     error - RCNOERROR    if all went well.
  2319. *            RCNOMESH     if the handle is not valid.
  2320. *
  2321. *   EXAMPLE
  2322. *    error = MWLMeshLightColorSet(meshhandle,&mycolor);
  2323. *
  2324. *   NOTES
  2325. *    The light will be used by some file formats only,
  2326. *    and for 2D or display functions.
  2327. *
  2328. *   BUGS
  2329. *   SEE ALSO
  2330. *     MWLMeshLightColorGet(),MWLMeshLightPositionSet()
  2331. *    MWLMeshLightPositionGet()
  2332. ******************************************************************************
  2333. *
  2334. */
  2335. ULONG __saveds ASM MWLMeshLightColorSet(register __d1 ULONG meshhandle,
  2336.                                             register __a0 TOCLColor *color) {
  2337.     TOCLMesh    *mesh=NULL;
  2338.     TOCLColor    *mcolor=NULL;
  2339.     
  2340.     // make a copy of color, a0 is a scratch register
  2341.     mcolor=color;
  2342.   
  2343.     mesh=(TOCLMesh *) meshhandle;
  2344.     if(mesh==NULL) return(RCNOMESH);
  2345.     
  2346.     mesh->light.color=(*mcolor);
  2347.  
  2348.     return(RCNOERROR);
  2349. }
  2350.  
  2351. /****** meshwriter.library/MWLMeshLightColorGet ******************************************
  2352. *   NAME    
  2353. *     MWLMeshLightColorGet -- Get the color of the light source.
  2354. *   SYNOPSIS
  2355. *    error = MWLMeshLightColorGet( meshhandle,color )
  2356. *                                  D1          A0
  2357. *
  2358. *    ULONG MWLMeshLightColorGet
  2359. *         ( ULONG,TOCLColor * );
  2360. *
  2361. *   FUNCTION
  2362. *    The color of the light source will be written in the passed color structure.
  2363. *   INPUTS
  2364. *     meshhandle      - A valid handle of a mesh.
  2365. *    color           - Pointer to a color structure which will contain
  2366. *                      the color information.
  2367. *    
  2368. *   RESULT
  2369. *     error - RCNOERROR    if all went well.
  2370. *            RCNOMESH     if the handle is not valid.
  2371. *
  2372. *   EXAMPLE
  2373. *    error = MWLMeshLightColorGet(meshhandle,&mycolor);
  2374. *
  2375. *   NOTES
  2376. *    The light will be used by some file formats only,
  2377. *    and for 2D or display functions.
  2378. *
  2379. *   BUGS
  2380. *   SEE ALSO
  2381. *     MWLMeshLightColorSet(),MWLMeshLightPositionSet()
  2382. *    MWLMeshLightPositionGet()
  2383. ******************************************************************************
  2384. *
  2385. */
  2386. ULONG __saveds ASM MWLMeshLightColorGet(register __d1 ULONG meshhandle,
  2387.                                             register __a0 TOCLColor *color) {
  2388.     TOCLMesh    *mesh=NULL;
  2389.     TOCLColor    *mcolor=NULL;
  2390.     
  2391.     // make a copy of color, a0 is a scratch register
  2392.     mcolor=color;
  2393.  
  2394.     mesh=(TOCLMesh *) meshhandle;
  2395.     if(mesh==NULL) return(RCNOMESH);
  2396.  
  2397.     (*color)=mesh->light.color;
  2398.     
  2399.     return(RCNOERROR);
  2400. }
  2401.  
  2402. /****** meshwriter.library/MWL3DFileFormatNamesGet ******************************************
  2403. *   NAME    
  2404. *     MWL3DFileFormatNamesGet -- Get a name list of all supported 3D file formats.
  2405. *   SYNOPSIS
  2406. *    list = MWL3DFileFormatNamesGet(  )
  2407. *
  2408. *    STRPTR * MWL3DFileFormatNamesGet
  2409. *         (  );
  2410. *
  2411. *   FUNCTION
  2412. *    You will get a pointer to the namelist of all supported 3D file formats.
  2413. *    This strings are READ_ONLY and only valid as long as the library is opened.
  2414. *
  2415. *    The list is sorted alphabetically.
  2416. *
  2417. *    The resulting pointer can directly be used to fill up cycle or list gadgets
  2418. *    for example.
  2419. *   INPUTS
  2420. *    
  2421. *   RESULT
  2422. *     list - A NULL terminated array of string pointers. Or NULL if no
  2423. *           files are supported.
  2424. *
  2425. *   EXAMPLE
  2426. *    list = MWL3DFileFormatNamesGet();
  2427. *
  2428. *   NOTES
  2429. *
  2430. *   BUGS
  2431. *   SEE ALSO
  2432. *     MWL3DFileFormatIDGet(),MWL3DFileFormatExtensionGet()
  2433. *    MWL3DFileFormatNumberOfGet()
  2434. ******************************************************************************
  2435. *
  2436. */
  2437. STRPTR * __saveds ASM MWL3DFileFormatNamesGet() {
  2438.     if(c3dFFNames[0]!=NULL) return(c3dFFNames);
  2439.     return(NULL);
  2440. }
  2441.  
  2442. /****** meshwriter.library/MWL3DFileFormatIDGet ******************************************
  2443. *   NAME    
  2444. *     MWL3DFileFormatIDGet -- Get the ID of a specific 3D file format.
  2445. *   SYNOPSIS
  2446. *    id = MWL3DFileFormatIDGet( ffname )
  2447. *                                D1
  2448. *
  2449. *    ULONG MWL3DFileFormatIDGet
  2450. *         ( STRPTR );
  2451. *
  2452. *   FUNCTION
  2453. *    You will get the ID of the 3D file format of which you passed its name.
  2454. *   INPUTS
  2455. *    ffname - Name of the format you search the ID for.
  2456. *    
  2457. *   RESULT
  2458. *     id - The ID of the 3D file format or 0 if not found/supported.
  2459. *
  2460. *   EXAMPLE
  2461. *    id = MWL3DFileFormatIDGet("Lightwave");
  2462. *
  2463. *   NOTES
  2464. *    Even if the values of the IDs wont change in future versions, it is
  2465. *    recomended to show the list of all names to the user and let him choose
  2466. *    the format. With the help of this function you will get the correct
  2467. *    ID which is needed for further function calls.
  2468. *
  2469. *   BUGS
  2470. *   SEE ALSO
  2471. *     MWL3DFileFormatNamesGet(),MWL3DFileFormatExtensionGet()
  2472. *    MWL3DFileFormatNumberOfGet()
  2473. ******************************************************************************
  2474. *
  2475. */
  2476. ULONG __saveds ASM MWL3DFileFormatIDGet(register __d1 STRPTR ffname) {
  2477.     ULONG i;
  2478.         
  2479.     i=0;
  2480.     while(strcmp(c3dFFNames[i],ffname) && c3dFFNames[i]!=NULL) {i++};
  2481.     
  2482.     // check if we got it or not
  2483.     if(!strcmp(c3dFFNames[i],ffname)) return(c3dFFIDs[i]);
  2484.     else return(0);
  2485. }
  2486.  
  2487. /****** meshwriter.library/MWL3DFileFormatExtensionGet ******************************************
  2488. *   NAME    
  2489. *     MWL3DFileFormatExtensionGet -- Get the file extension of a specific 3D file format.
  2490. *   SYNOPSIS
  2491. *    ext = MWL3DFileFormatExtensionGet( ffid )
  2492. *                                       D1
  2493. *
  2494. *    STRPTR MWL3DFileFormatExtensionGet
  2495. *         ( ULONG );
  2496. *
  2497. *   FUNCTION
  2498. *    You will get a pointer to the extension of the specified 3D file format.
  2499. *    This strings are READ_ONLY and only valid as long as the library is opened.
  2500. *   INPUTS
  2501. *    ffid - ID of the file format you search the extension for.
  2502. *    
  2503. *   RESULT
  2504. *     ext - Pointer to the file extension string or NULL if the format is unknown.
  2505. *
  2506. *   EXAMPLE
  2507. *    ext = MWL3DFileFormatExtensionGet(id);
  2508. *
  2509. *   NOTES
  2510. *    This extensions are proposals of the format creators, but you are free
  2511. *    to use them.
  2512. *
  2513. *   BUGS
  2514. *   SEE ALSO
  2515. *     MWL3DFileFormatNamesGet(),MWL3DFileFormatIDGet()
  2516. *    MWL3DFileFormatNumberOfGet()
  2517. ******************************************************************************
  2518. *
  2519. */
  2520. STRPTR __saveds ASM MWL3DFileFormatExtensionGet(register __d1 ULONG ffid) {
  2521.     ULONG i,mffid;
  2522.         
  2523.     // make a copy of ffid, because d1 is a scratch register
  2524.     mffid=ffid;
  2525.         
  2526.     i=0;
  2527.     while(c3dFFIDs[i]!=mffid && c3dFFIDs[i]!=0) {i++};
  2528.     
  2529.     // check if we got it or not
  2530.     if(c3dFFIDs[i]==mffid) return(c3dFFExtensions[i]);
  2531.     else return(NULL);
  2532. }
  2533.  
  2534. /****** meshwriter.library/MWL3DFileFormatNumberOfGet ******************************************
  2535. *   NAME    
  2536. *     MWL3DFileFormatNumberOfGet -- Get the number of supported 3D file formats.
  2537. *   SYNOPSIS
  2538. *    number = MWL3DFileFormatNumberOfGet( )
  2539. *
  2540. *    ULONG MWL3DFileFormatNumberOfGet
  2541. *         ( );
  2542. *
  2543. *   FUNCTION
  2544. *    You will get the number of supported 3D file formats of this library version.
  2545. *   INPUTS
  2546. *    
  2547. *   RESULT
  2548. *     number - Number of supported file formats or 0 if none.
  2549. *
  2550. *   EXAMPLE
  2551. *    number = MWL3DFileFormatNumberOfGet();
  2552. *
  2553. *   NOTES
  2554. *
  2555. *   BUGS
  2556. *   SEE ALSO
  2557. *     MWL3DFileFormatNamesGet(),MWL3DFileFormatIDGet()
  2558. *    MWL3DFileFormatNumberExtensionGet()
  2559. ******************************************************************************
  2560. *
  2561. */
  2562. ULONG __saveds ASM MWL3DFileFormatNumberOfGet() {
  2563.     ULONG  i;
  2564.     STRPTR *sIndex=NULL;
  2565.  
  2566.     i=0;
  2567.     sIndex=c3dFFNames;
  2568.     while (sIndex[i]!=NULL) i++;
  2569.     
  2570.     return(i);
  2571. }
  2572.  
  2573. /****** meshwriter.library/MWLMeshSave3D ******************************************
  2574. *   NAME    
  2575. *     MWLMeshSave3D -- Saves the mesh as 3D file..
  2576. *
  2577. *   SYNOPSIS
  2578. *    error = MWLMeshSave3D( meshhandle,id,filename,taglist )
  2579. *                           D1         D2 D3        A0
  2580. *
  2581. *    ULONG MWLMeshSave3D
  2582. *         ( ULONG,ULONG,STRPTR,struct TagItem * );
  2583. *
  2584. *   FUNCTION
  2585. *    The mesh, this means vertices, polygons, materials, camera and light will
  2586. *    be saved in the specified 3d file format.
  2587. *   INPUTS
  2588. *     meshhandle  - A valid handle of a mesh.
  2589. *    id          - A valid 3D file format id, to spedify the output format.
  2590. *    filename    - Name and path of the file.
  2591. *    taglist     - NULL, for future use.
  2592. *    
  2593. *   RESULT
  2594. *    error - RCNOERROR                  if all went well.
  2595. *            RCNOMESH                   if the handle is not valid.
  2596. *            RCUNKNOWNFTYPE             if the id is not known.
  2597. *            RCNOPOLYGON                if there are no polygons to save.
  2598. *            RCCHGBUF                   if an error occured to allocate the save buffer.
  2599. *            RCWRITEDATA                if an error occured while writing data, no more space...
  2600. *            RCVERTEXOVERFLOW           if the format does not support as much vertices.
  2601. *            RCVERTEXINPOLYGONOVERFLOW  if the format does not support as much vertices in a polygon.
  2602. *            IoErr()                    if possible to catch it, you will get its codes.
  2603. *
  2604. *   EXAMPLE
  2605. *    error = MWLMeshSave3D(meshhandle,id,"ram:test",NULL);
  2606. *
  2607. *   NOTES
  2608. *    No file existence tests are made here! Existent files will be overwritten.
  2609. *
  2610. *   BUGS
  2611. *   SEE ALSO
  2612. *     MWL3DFileFormatIDGet(),MWLMeshSave2D()
  2613. ******************************************************************************
  2614. *
  2615. */
  2616. ULONG __saveds ASM MWLMeshSave3D(register __d1 ULONG meshhandle,
  2617.                                     register __d2 ULONG id,
  2618.                                     register __d3 STRPTR filename,
  2619.                                     register __a0 struct TagItem *taglist) {
  2620.     TOCLMesh        *mesh;
  2621.     BPTR            filehandle=NULL;
  2622.     ULONG            retcode=RCNOERROR;
  2623.     UBYTE            i;
  2624.     struct TagItem    *mtaglist=NULL;
  2625.     
  2626.     // make a copy of taglist, a0 is a scratch register
  2627.     mtaglist=taglist;
  2628.  
  2629.     mesh = (TOCLMesh *) meshhandle;
  2630.     if(mesh==NULL) return(RCNOMESH);    
  2631.  
  2632.       /*
  2633.       ** If there are no polygons, so leave
  2634.       */
  2635.     if(mesh->polygons.firstNode==NULL) return(RCNOPOLYGON);
  2636.     
  2637.     /*
  2638.     ** Check if the filetype is valid
  2639.     */
  2640.     i=0;
  2641.     while(c3dFFIDs[i]!=id && c3dFFIDs[i]!=0) {i++};
  2642.     if(c3dFFIDs[i]!=id || id==0) return(RCUNKNOWNFTYPE);
  2643.     
  2644.     /*
  2645.     ** If no camera and light position was given, set it to default now
  2646.     */
  2647.     if (!(mesh->camera.position.x &&
  2648.          mesh->camera.position.y &&
  2649.          mesh->camera.position.z &&
  2650.          mesh->camera.lookat.x &&
  2651.          mesh->camera.lookat.y &&
  2652.          mesh->camera.lookat.z &&
  2653.          mesh->light.position.x &&
  2654.          mesh->light.position.y &&
  2655.          mesh->light.position.z)) setCameraLight(mesh);
  2656.  
  2657.     /*
  2658.     ** Open the file 
  2659.     */
  2660.     /* Open the file for text output */
  2661.     if((filehandle=Open(filename,MODE_NEWFILE))==NULL) return(IoErr());
  2662.  
  2663.     /* Change the buffer size of the filehandle to 10k */
  2664.     if (SetVBuf(filehandle,NULL,BUF_FULL,10000)!=DOSFALSE) {
  2665.         Close(filehandle);
  2666.         return(RCCHGBUF);
  2667.     }
  2668.  
  2669.     /*
  2670.     ** Write the mesh
  2671.     */
  2672.     switch(id) {
  2673.         case T3DFRAWA :
  2674.             retcode = write3RAWA(filehandle,mesh);
  2675.             break;
  2676.         case T3DFRAWB :
  2677.             retcode = write3RAWB(filehandle,mesh);
  2678.             break;
  2679.         case T3DFDXF :
  2680.             retcode = write3DXF(filehandle,mesh);
  2681.             break;
  2682.         case T3DFVRML1 :
  2683.             retcode = write3VRML1(filehandle,mesh);
  2684.             break;
  2685.         case T3DFPOV3 :
  2686.             retcode = write3POV3(filehandle,mesh);
  2687.             break;
  2688.         case T3DFTDDD :
  2689.             retcode = write3TDDD(filehandle,mesh);
  2690.             break;
  2691.         case T3DFTDDDH :
  2692.             retcode = write3TDDDH(filehandle,mesh);
  2693.             break;
  2694.         case T3DFREF4 :
  2695.             retcode = write3REF4(filehandle,mesh);
  2696.             break;
  2697.         case T3DFLWOB :
  2698.             retcode = write3LWOB(filehandle,mesh);
  2699.             break;
  2700.         case T3DFGEOA :
  2701.             retcode = write3GEOA(filehandle,mesh);
  2702.             break;
  2703. //        case T3DFREAL :
  2704. //            retcode = write3REAL(filehandle,mesh);
  2705. //            break;
  2706.     }
  2707.     
  2708.     /*
  2709.     ** Close the file
  2710.     */
  2711.     Close(filehandle);
  2712.     
  2713.     return(retcode);
  2714. }
  2715.  
  2716. /****** meshwriter.library/MWL2DFileFormatNamesGet ******************************************
  2717. *   NAME    
  2718. *     MWL2DFileFormatNamesGet -- Get a name list of all supported 2D file formats.
  2719. *   SYNOPSIS
  2720. *    list = MWL2DFileFormatNamesGet(  )
  2721. *
  2722. *    STRPTR * MWL2DFileFormatNamesGet
  2723. *         (  );
  2724. *
  2725. *   FUNCTION
  2726. *    You will get a pointer to the namelist of all supported 2D file formats.
  2727. *    This strings are READ_ONLY and only valid as long as the library is opened.
  2728. *
  2729. *    The list is sorted alphabetically.
  2730. *
  2731. *    The resulting pointer can directly be used to fill up cycle or list gadgets
  2732. *    for example.
  2733. *   INPUTS
  2734. *    
  2735. *   RESULT
  2736. *     list - A NULL terminated array of string pointers. Or NULL if no
  2737. *           files are supported.
  2738. *
  2739. *   EXAMPLE
  2740. *    list = MWL2DFileFormatNamesGet();
  2741. *
  2742. *   NOTES
  2743. *
  2744. *   BUGS
  2745. *   SEE ALSO
  2746. *     MWL2DFileFormatIDGet(),MWL2DFileFormatExtensionGet()
  2747. *    MWL2DFileFormatNumberOfGet()
  2748. ******************************************************************************
  2749. *
  2750. */
  2751. STRPTR * __saveds ASM MWL2DFileFormatNamesGet() {
  2752.     if(c2dFFNames[0]!=NULL) return(c2dFFNames);
  2753.     return(NULL);
  2754. }
  2755.  
  2756. /****** meshwriter.library/MWL2DFileFormatIDGet ******************************************
  2757. *   NAME    
  2758. *     MWL2DFileFormatIDGet -- Get the ID of a specific 2D file format.
  2759. *   SYNOPSIS
  2760. *    id = MWL2DFileFormatIDGet( ffname )
  2761. *                               D1
  2762. *
  2763. *    ULONG MWL2DFileFormatIDGet
  2764. *         ( STRPTR );
  2765. *
  2766. *   FUNCTION
  2767. *    You will get the ID of the 2D file format of which you passed its name.
  2768. *   INPUTS
  2769. *    ffname - Name of the format you search the ID for.
  2770. *    
  2771. *   RESULT
  2772. *     id - The ID of the 2D file format or 0 if not found/supported.
  2773. *
  2774. *   EXAMPLE
  2775. *    id = MWL2DFileFormatIDGet("PostScript");
  2776. *
  2777. *   NOTES
  2778. *    Even if the values of the IDs wont change in future versions, it is
  2779. *    recomended to show the list of all names to the user and let him choose
  2780. *    the format. With the help of this function you will get the correct
  2781. *    ID which is needed for further function calls.
  2782. *
  2783. *   BUGS
  2784. *   SEE ALSO
  2785. *     MWL2DFileFormatNamesGet(),MWL2DFileFormatExtensionGet()
  2786. *    MWL2DFileFormatNumberOfGet()
  2787. ******************************************************************************
  2788. *
  2789. */
  2790. ULONG __saveds ASM MWL2DFileFormatIDGet(register __d1 STRPTR ffname) {
  2791.     ULONG i;
  2792.     STRPTR mffname=NULL;
  2793.  
  2794.     // make a copy of ffname, d1 is a scratch register
  2795.     mffname=ffname;
  2796.  
  2797.     i=0;
  2798.     while(strcmp(c2dFFNames[i],mffname) && c2dFFNames[i]!=NULL) {i++};
  2799.     
  2800.     // check if we got it or not
  2801.     if(!strcmp(c2dFFNames[i],mffname)) return(c2dFFIDs[i]);
  2802.     else return(0);
  2803. }
  2804.  
  2805. /****** meshwriter.library/MWL2DFileFormatExtensionGet ******************************************
  2806. *   NAME    
  2807. *     MWL2DFileFormatExtensionGet -- Get the file extension of a specific 2D file format.
  2808. *   SYNOPSIS
  2809. *    ext = MWL2DFileFormatExtensionGet( ffid )
  2810. *                                       D1
  2811. *
  2812. *    STRPTR MWL2DFileFormatExtensionGet
  2813. *         ( ULONG );
  2814. *
  2815. *   FUNCTION
  2816. *    You will get a pointer to the extension of the specified 2D file format.
  2817. *    This strings are READ_ONLY and only valid as long as the library is opened.
  2818. *   INPUTS
  2819. *    ffid - ID of the format you search the extension for.
  2820. *    
  2821. *   RESULT
  2822. *     ext - Pointer to the file extension string or NULL if the format is unknown.
  2823. *
  2824. *   EXAMPLE
  2825. *    ext = MWL2DFileFormatExtensionGet(id);
  2826. *
  2827. *   NOTES
  2828. *    This extensions are proposals of the format creators, but you are free
  2829. *    to use them.
  2830. *
  2831. *   BUGS
  2832. *   SEE ALSO
  2833. *     MWL2DFileFormatNamesGet(),MWL2DFileFormatIDGet()
  2834. *    MWL2DFileFormatNumberOfGet()
  2835. ******************************************************************************
  2836. *
  2837. */
  2838. STRPTR __saveds ASM MWL2DFileFormatExtensionGet(register __d1 ULONG ffid) {
  2839.     ULONG i,mffid;
  2840.  
  2841.     // make a copy of ffid, d1 is a scratch register
  2842.     mffid=ffid;
  2843.     
  2844.     i=0;
  2845.     while(c2dFFIDs[i]!=mffid && c2dFFIDs[i]!=0) {i++};
  2846.     
  2847.     // check if we got it or not
  2848.     if(c2dFFIDs[i]==mffid) return(c2dFFExtensions[i]);
  2849.     else return(NULL);
  2850. }
  2851.  
  2852. /****** meshwriter.library/MWL2DFileFormatNumberOfGet ******************************************
  2853. *   NAME    
  2854. *     MWL2DFileFormatNumberOfGet -- Get the number of supported 2D file formats.
  2855. *   SYNOPSIS
  2856. *    number = MWL2DFileFormatNumberOfGet( )
  2857. *
  2858. *    ULONG MWL2DFileFormatNumberOfGet
  2859. *         ( );
  2860. *
  2861. *   FUNCTION
  2862. *    You will get the number of supported 2D file formats of this library version.
  2863. *   INPUTS
  2864. *    
  2865. *   RESULT
  2866. *     number - Number of supported file formats or 0 if none.
  2867. *
  2868. *   EXAMPLE
  2869. *    number = MWL2DFileFormatNumberOfGet();
  2870. *
  2871. *   NOTES
  2872. *
  2873. *   BUGS
  2874. *   SEE ALSO
  2875. *     MWL2DFileFormatNamesGet(),MWL2DFileFormatIDGet()
  2876. *    MWL2DFileFormatNumberExtensionGet()
  2877. ******************************************************************************
  2878. *
  2879. */
  2880. ULONG __saveds ASM MWL2DFileFormatNumberOfGet() {
  2881.     ULONG  i;
  2882.     STRPTR *sIndex=NULL;
  2883.  
  2884.     i=0;
  2885.     sIndex=c2dFFNames;
  2886.     while (sIndex[i]!=NULL) i++;
  2887.     
  2888.     return(i);
  2889. }
  2890.  
  2891. /****** meshwriter.library/MWLMeshSave2D ******************************************
  2892. *   NAME    
  2893. *     MWLMeshSave2D -- Saves the mesh as 2D file.
  2894. *
  2895. *   SYNOPSIS
  2896. *    error = MWLMeshSave2D( meshhandle,id,filename,viewtype,drawmode,taglist )
  2897. *                           D1         D2 D3       D4       D5        A0
  2898. *
  2899. *    ULONG MWLMeshSave2D
  2900. *         ( ULONG,ULONG,STRPTR,ULONG,ULONG,struct TagItem * );
  2901. *
  2902. *   FUNCTION
  2903. *    The mesh, this means vertices, polygons, materials, camera and light will
  2904. *    be used to generate and save a 2D file from a specific view point and
  2905. *    drawing mode.
  2906. *   INPUTS
  2907. *     meshhandle  - A valid handle of a mesh.
  2908. *    id          - A valid 2D file format id, to specify the output format.
  2909. *    filename    - Name and path of the file.
  2910. *    viewtype    - Type of view, like perspective, or top ...
  2911. *    drawmode    - Type of drawing, points, lines, surfaces ...
  2912. *    taglist     - NULL, for future use.
  2913. *    
  2914. *   RESULT
  2915. *    error - RCNOERROR         if all went well.
  2916. *            RCNOMESH          if the handle is not valid.
  2917. *            RCUNKNOWNFTYPE    if the id is not known.
  2918. *            RCUNKNOWNDMODE    if the view mode in not known.
  2919. *            RCNOPOLYGON       if there are no polygons to save.
  2920. *            RCCHGBUF          if an error occured to allocate the save buffer.
  2921. *            RCWRITEDATA       if an error occured while writing data, no more space...
  2922. *            RCVERTEXOVERFLOW  if the format does not support as much vertices.
  2923. *            IoErr()           if possible to catch it, you will get its codes.
  2924. *
  2925. *   EXAMPLE
  2926. *    error = MWLMeshSave2D(meshhandle,id,"ram:test",TVWPERSP,dm,NULL);
  2927. *
  2928. *   NOTES
  2929. *    No file existence tests are made here! Existent files will be overwritten.
  2930. *
  2931. *   BUGS
  2932. *   SEE ALSO
  2933. *     MWL2DFileFormatIDGet(),MWLDrawModeGet(),MWLMeshSave3D()
  2934. ******************************************************************************
  2935. *
  2936. */
  2937. ULONG __saveds ASM MWLMeshSave2D(register __d1 ULONG meshhandle,
  2938.                                     register __d2 ULONG id,
  2939.                                     register __d3 STRPTR filename,
  2940.                                     register __d4 ULONG viewtype,
  2941.                                     register __d5 ULONG drawmode,
  2942.                                     register __a0 struct TagItem *taglist) {
  2943.     TOCLMesh        *mesh;
  2944.     BPTR            filehandle=NULL;
  2945.     ULONG            retcode=RCNOERROR;
  2946.     UBYTE            i;
  2947.     struct TagItem    *mtaglist=NULL;
  2948.     
  2949.     // make a copy of taglist, a0 is a scratch register
  2950.     mtaglist=taglist;
  2951.  
  2952.     mesh = (TOCLMesh *) meshhandle;
  2953.     if(mesh==NULL) return(RCNOMESH);    
  2954.  
  2955.       /*
  2956.       ** If there are no polygons, so leave
  2957.       */
  2958.     if(mesh->polygons.firstNode==NULL) return(RCNOPOLYGON);
  2959.     
  2960.     /*
  2961.     ** Check if the filetype is valid
  2962.     */
  2963.     i=0;
  2964.     while(c2dFFIDs[i]!=id && c2dFFIDs[i]!=0) {i++};
  2965.     if(c2dFFIDs[i]!=id || id==0) return(RCUNKNOWNFTYPE);
  2966.     
  2967.     /*
  2968.     ** Check if the viewtype is valid
  2969.     */
  2970.     if(!(viewtype==TVWTOP ||
  2971.         viewtype==TVWBOTTOM ||
  2972.         viewtype==TVWLEFT ||
  2973.         viewtype==TVWRIGHT ||
  2974.         viewtype==TVWFRONT ||
  2975.         viewtype==TVWBACK ||
  2976.         viewtype==TVWPERSP)) return(RCUNKNOWNVTYPE);
  2977.  
  2978.     /*
  2979.     ** Check if the drawmode is valid
  2980.     */
  2981.     i=0;
  2982.     while(cDMIDs[i]!=drawmode && cDMIDs[i]!=0) {i++};
  2983.     if(cDMIDs[i]!=drawmode || drawmode==0) return(RCUNKNOWNDMODE);
  2984.     
  2985.     /*
  2986.     ** If no camera and light position was given, set it to default now
  2987.     */
  2988.     if (!(mesh->camera.position.x &&
  2989.          mesh->camera.position.y &&
  2990.          mesh->camera.position.z &&
  2991.          mesh->camera.lookat.x &&
  2992.          mesh->camera.lookat.y &&
  2993.          mesh->camera.lookat.z &&
  2994.          mesh->light.position.x &&
  2995.          mesh->light.position.y &&
  2996.          mesh->light.position.z)) setCameraLight(mesh);
  2997.  
  2998.     /*
  2999.     ** Open the file 
  3000.     */
  3001.     /* Open the file for text output */
  3002.     if((filehandle=Open(filename,MODE_NEWFILE))==NULL) return(IoErr());
  3003.  
  3004.     /* Change the buffer size of the filehandle to 10k */
  3005.     if (SetVBuf(filehandle,NULL,BUF_FULL,10000)!=DOSFALSE) {
  3006.         Close(filehandle);
  3007.         return(RCCHGBUF);
  3008.     }
  3009.  
  3010.     /*
  3011.     ** Write the mesh
  3012.     */
  3013.     switch(id) {
  3014. //        case T2DFEPS :
  3015. //            retcode = write2EPS(filehandle,mesh,viewtype,drawmode);
  3016. //            break;        
  3017. //        case T2DFPSP :
  3018. //            retcode = write2PSP(filehandle,mesh,viewtype,drawmode);
  3019. //            break;        
  3020. //        case T2DFPSL :
  3021. //            retcode = write2PSL(filehandle,mesh,viewtype,drawmode);
  3022. //            break;        
  3023.     }
  3024.     
  3025.     /*
  3026.     ** Close the file
  3027.     */
  3028.     Close(filehandle);
  3029.     
  3030.     return(retcode);
  3031. }
  3032.  
  3033. /****** meshwriter.library/MWLDrawModeNamesGet ******************************************
  3034. *   NAME 
  3035. *        MWLDrawModeNamesGet -- Get a name list of all supported drawing modes.
  3036. *   SYNOPSIS
  3037. *        list = MWLDrawModeNamesGet(  )
  3038. *
  3039. *        STRPTR * MWLDrawModeNamesGet
  3040. *             (  );
  3041. *
  3042. *   FUNCTION
  3043. *        You will get a pointer to the namelist of all supported drawing modes.
  3044. *        This strings are READ_ONLY and only valid as long as the library is opened.
  3045. *
  3046. *        The resulting pointer can directly be used to fill up cycle or list gadgets
  3047. *        for example.
  3048. *
  3049. *   INPUTS
  3050. *        
  3051. *   RESULT
  3052. *        list - A NULL terminated array of string pointers. Or NULL if no
  3053. *               modes are supported.
  3054. *
  3055. *   EXAMPLE
  3056. *        list = MWLDrawModeNamesGet();
  3057. *
  3058. *   NOTES
  3059. *
  3060. *   BUGS
  3061. *   SEE ALSO
  3062. *        MWLDrawModeIDGet(),MWLDrawModeNumberOfGet()
  3063. ******************************************************************************
  3064. *
  3065. */
  3066. STRPTR * __saveds ASM MWLDrawModeNamesGet() {
  3067.     if(cDMNames[0]!=NULL) return(cDMNames);
  3068.     return(NULL);
  3069. }
  3070.  
  3071. /****** meshwriter.library/MWLDrawModeIDGet ******************************************
  3072. *   NAME 
  3073. *        MWLDrawModeIDGet -- Get the ID of a specific drawing mode.
  3074. *   SYNOPSIS
  3075. *        id = MWLDrawModeIDGet( dmname )
  3076. *                               D1
  3077. *
  3078. *        ULONG MWLDrawModeIDGet
  3079. *             ( STRPTR );
  3080. *
  3081. *   FUNCTION
  3082. *        You will get the ID of the drawing mode of which you passed its name.
  3083. *   INPUTS
  3084. *        dm - Name of the drawing mode you search the ID for.
  3085. *        
  3086. *   RESULT
  3087. *        id - The ID of the drawing mode or 0 if not found/supported.
  3088. *
  3089. *   EXAMPLE
  3090. *        id = MWLDrawModeIDGet("Points");
  3091. *
  3092. *   NOTES
  3093. *        Even if the values of the IDs wont change in future versions, it is
  3094. *        recomended to show the list of all names to the user and let him choose
  3095. *        the format. With the help of this function you will get the correct
  3096. *        ID which is needed for further function calls.
  3097. *
  3098. *   BUGS
  3099. *   SEE ALSO
  3100. *        MWLDrawModeNamesGet(),MWLDrawModeNumberOfGet()
  3101. ******************************************************************************
  3102. *
  3103. */
  3104. ULONG __saveds ASM MWLDrawModeIDGet(register __d1 STRPTR ffname) {
  3105.     ULONG i;
  3106.     STRPTR mffname=NULL;
  3107.  
  3108.     // make a copy of ffname, d1 is a scratch register
  3109.     mffname=ffname;
  3110.  
  3111.     i=0;
  3112.     while(strcmp(cDMNames[i],mffname) && cDMNames[i]!=NULL) {i++};
  3113.     
  3114.     // check if we got it or not
  3115.     if(!strcmp(cDMNames[i],mffname)) return(cDMIDs[i]);
  3116.     else return(0);
  3117. }
  3118.  
  3119. /****** meshwriter.library/MWLDrawModeNumberOfGet ******************************************
  3120. *   NAME 
  3121. *        MWLDrawModeNumberOfGet -- Get the number of supported drawing modes.
  3122. *   SYNOPSIS
  3123. *        number = MWLDrawModeNumberOfGet( )
  3124. *
  3125. *        ULONG MWLDrawModeNumberOfGet
  3126. *             ( );
  3127. *
  3128. *   FUNCTION
  3129. *        You will get the number of supported drawing modes of this library version.
  3130. *   INPUTS
  3131. *        
  3132. *   RESULT
  3133. *        number - Number of supported drawing modes or 0 if none.
  3134. *
  3135. *   EXAMPLE
  3136. *        number = MWLDrawModeNumberOfGet();
  3137. *
  3138. *   NOTES
  3139. *
  3140. *   BUGS
  3141. *   SEE ALSO
  3142. *        MWLDrawModeNamesGet(),MWLDrawModeIDGet()
  3143. ******************************************************************************
  3144. *
  3145. */
  3146. ULONG __saveds ASM MWLDrawModeNumberOfGet() {
  3147.     ULONG  i;
  3148.     STRPTR *sIndex=NULL;
  3149.  
  3150.     i=0;
  3151.     sIndex=cDMNames;
  3152.     while (sIndex[i]!=NULL) i++;
  3153.     
  3154.     return(i);
  3155. }
  3156.  
  3157. /****** meshwriter.library/MWLMeshVertexAdd *************************************************
  3158. *   NAME    
  3159. *     MWLMeshVertexAdd -- Add a new vertex to the mesh its vertex list according the CTM.
  3160. *
  3161. *   SYNOPSIS
  3162. *    error = MWLMeshVertexAdd( meshhandle,vertex,index )
  3163. *                              D1          A0    D2
  3164. *
  3165. *    ULONG MWLMeshVertexAdd
  3166. *         ( ULONG,TOCLVertex *,ULONG * );
  3167. *
  3168. *   FUNCTION
  3169. *    A new vertex will be added to the mesh its vertex list, without binding it to any
  3170. *    polygon, which can be made later.
  3171. *   INPUTS
  3172. *     meshhandle   - A valid handle of a mesh.
  3173. *    vertex       - Pointer to a vertex structure which contains the coordinates
  3174. *                   of the new vertex.
  3175. *    index        - Pointer to a variable which will contain the index of the vertex,
  3176. *                   which will be needed for further use.
  3177. *    
  3178. *   RESULT
  3179. *     error - RCNOERROR    if all went well.
  3180. *            RCNOMESH     if the handle is not valid.
  3181. *            RCNOMEMORY   if there is not enough memory. 
  3182. *   EXAMPLE
  3183. *    error = MWLMeshVertexAdd(meshhandle,&myvertex,&myindex);
  3184. *
  3185. *   NOTES
  3186. *    File formats which have an internal vertex list will get all vertices
  3187. *    of the mesh, even if they were never used in a polygon.
  3188. *
  3189. *   BUGS
  3190. *   SEE ALSO
  3191. *     MWLMeshPolygonVertexAssign()
  3192. ******************************************************************************
  3193. *
  3194. */
  3195. ULONG __saveds ASM MWLMeshVertexAdd(register __d1 ULONG meshhandle,
  3196.                                     register __a0 TOCLVertex *vertex,
  3197.                                     register __d2 ULONG *index) {
  3198.                                 
  3199.     TOCLMesh                    *mesh=NULL;
  3200.     TOCLVertexNode                *ver=NULL;
  3201.     TOCLVertex                    *mvertex=NULL;
  3202.       
  3203.     // make a copy of vertex, a0 is a scratch register
  3204.     mvertex=vertex;
  3205.     
  3206.     mesh=(TOCLMesh *) meshhandle;
  3207.     if (mesh==NULL) return(RCNOMESH);
  3208.  
  3209.     /*
  3210.     ** Add a new vertice to the internal vertice list
  3211.     */
  3212.     ver = addVertex(mesh,(*mvertex));
  3213.     if (ver==NULL) {
  3214.         return(RCNOMEMORY);
  3215.     }
  3216.  
  3217.     (*index)=ver->index;
  3218.  
  3219.     return(RCNOERROR);
  3220. }
  3221.  
  3222. /****** meshwriter.library/MWLMeshPolygonVertexAssign ***************************************
  3223. *   NAME    
  3224. *     MWLMeshPolygonVertexAssign -- Assigns an existing vertex to the most recent polygon.
  3225. *
  3226. *   SYNOPSIS
  3227. *    error = MWLMeshPolygonVertexAssign ( meshhandle,index )
  3228. *                                         D1         D2
  3229. *
  3230. *    ULONG MWLMeshPolygonAssign
  3231. *         ( ULONG,ULONG );
  3232. *
  3233. *   FUNCTION
  3234. *    An already existing vertex will be assigned to the polygon.
  3235. *   INPUTS
  3236. *     meshhandle   - A valid handle of a mesh.
  3237. *    index        - The index of the vertex.
  3238. *    
  3239. *   RESULT
  3240. *     error - RCNOERROR    if all went well.
  3241. *            RCNOMESH     if the handle is not valid.
  3242. *            RCNOMEMORY   if there is not enough memory. 
  3243. *            RCNOPOLYGON  if there is no polygon to work with.
  3244. *            RCNOVERTEX   if the vertex is not existing.
  3245. *   EXAMPLE
  3246. *    error = MWLMeshPolygonVertexAssign(meshhandle,index);
  3247. *
  3248. *   NOTES
  3249. *    Vertices have to be assigned in counterclock wise direction.
  3250. *
  3251. *          v3
  3252. *         / |
  3253. *        /  |
  3254. *       /   |
  3255. *      /    |
  3256. *     /     |
  3257. *    v1--->v2
  3258. *
  3259. *
  3260. *   BUGS
  3261. *   SEE ALSO
  3262. *     MWLMeshVertexAdd()
  3263. ******************************************************************************
  3264. *
  3265. */
  3266. ULONG __saveds ASM MWLMeshPolygonVertexAssign(register __d1 ULONG meshhandle,
  3267.                                                 register __d2 ULONG index) {
  3268.                                 
  3269.     TOCLMesh                    *mesh=NULL;
  3270.     TOCLVertexNode                *ver=NULL;
  3271.     TOCLPolygonsVerticesNode    *plv=NULL;
  3272.     TOCLPolygonNode            *pln=NULL;
  3273.       
  3274.     mesh=(TOCLMesh *) meshhandle;
  3275.     if (mesh==NULL) return(RCNOMESH);
  3276.  
  3277.     if(mesh->polygons.lastNode==NULL) return(RCNOPOLYGON); /* There is no polygon to work with */
  3278.  
  3279.     ver=getVertex(mesh,index);
  3280.     if(ver==NULL) return(RCNOVERTEX); /* The vertex does not exist */
  3281.  
  3282.     /*
  3283.     ** Add a new polygon vertex node to the polygon list its last element
  3284.     */
  3285.     plv = AllocPooled(mesh->polygonverticespool,sizeof(TOCLPolygonsVerticesNode));
  3286.     if (plv==NULL) {
  3287.         return(RCNOMEMORY);
  3288.     }
  3289.         
  3290.     plv->vertexNode=ver;
  3291.     plv->next=NULL;
  3292.  
  3293.     pln=mesh->polygons.lastNode;
  3294.      
  3295.     if(pln->firstNode!=NULL) {   /* Check if this is the first vertex to insert or not */
  3296.         pln->lastNode->next=plv;
  3297.         pln->lastNode=plv;
  3298.     }
  3299.     else {
  3300.         pln->lastNode=plv;
  3301.         pln->firstNode=plv;
  3302.     }
  3303.     
  3304.     /*
  3305.     ** Increment the number of vertices counter of the polygon
  3306.     */
  3307.     pln->numberOfVertices++;
  3308.         
  3309.     return(RCNOERROR);
  3310. }
  3311.  
  3312. /****** meshwriter.library/MWLMeshCTMReset **********************************************
  3313. *   NAME    
  3314. *     MWLMeshCTMReset -- Resets the current transformation matrix and the scale.
  3315. *
  3316. *   SYNOPSIS
  3317. *    error = MWLMeshCTMReset( meshhandle )
  3318. *                             D1
  3319. *
  3320. *    ULONG MWLMeshCTMReset
  3321. *         ( ULONG );
  3322. *
  3323. *   FUNCTION
  3324. *    The translation, rotation and scale factors will be set to the default values.
  3325. *    Translation is 0, rotation is 0 and scale is 1, for all axis.
  3326. *
  3327. *   INPUTS
  3328. *     meshhandle   - A valid handle of a mesh.
  3329. *    
  3330. *   RESULT
  3331. *     error - RCNOERROR          if all went well.
  3332. *            RCNOMESH           if the handle is not valid.
  3333. *   EXAMPLE
  3334. *    error = MWLMeshCTMReset(meshhandle);
  3335. *
  3336. *   NOTES
  3337. *
  3338. *   BUGS
  3339. *   SEE ALSO
  3340. *     MWLMeshTranslationChange(), MWLMeshTranslationGet()
  3341. *    MWLMeshRotationChange(),MWLMeshRotationGet()
  3342. *    MWLMeshScaleChange(),MWLMeshScaleGet()
  3343. ******************************************************************************
  3344. *
  3345. */
  3346. ULONG __saveds ASM MWLMeshCTMReset(register __d1 ULONG meshhandle) {
  3347.     TOCLMesh                    *mesh=NULL;
  3348.       
  3349.     mesh=(TOCLMesh *) meshhandle;
  3350.     if (mesh==NULL) return(RCNOMESH);
  3351.  
  3352.     mesh->ctm.sx=1,mesh->ctm.sy=1,mesh->ctm.sz=1;
  3353.     mesh->ctm.rx=0,mesh->ctm.ry=0,mesh->ctm.rz=0;
  3354.     mesh->ctm.m[0][0]=1,mesh->ctm.m[1][0]=0,mesh->ctm.m[2][0]=0,mesh->ctm.m[3][0]=0;
  3355.     mesh->ctm.m[0][1]=0,mesh->ctm.m[1][1]=1,mesh->ctm.m[2][1]=0,mesh->ctm.m[3][1]=0;
  3356.     mesh->ctm.m[0][2]=0,mesh->ctm.m[1][2]=0,mesh->ctm.m[2][2]=1,mesh->ctm.m[3][2]=0;
  3357.     mesh->ctm.m[0][3]=0,mesh->ctm.m[1][3]=0,mesh->ctm.m[2][3]=0,mesh->ctm.m[3][3]=1;
  3358.     
  3359.     return(RCNOERROR);
  3360. }
  3361.  
  3362. /****** meshwriter.library/MWLMeshTranslationChange *****************************************
  3363. *   NAME    
  3364. *     MWLMeshTranslationChange -- Changes the translation of the CTM of the mesh.
  3365. *
  3366. *   SYNOPSIS
  3367. *    error = MWLMeshTranslationChange( meshhandle,translation,operation )
  3368. *                                      D1          A0         D2
  3369. *
  3370. *    ULONG MWLMeshTranslationChange
  3371. *         ( ULONG,TOCLVertex *,ULONG );
  3372. *
  3373. *   FUNCTION
  3374. *    The translation of the CTM will be modified in function of the translation
  3375. *    and the operation to perform.
  3376. *   INPUTS
  3377. *     meshhandle  - A valid handle of a mesh.
  3378. *    translation - Pointer to a vertex structure which contains the coordinates
  3379. *                  of the translation.
  3380. *    operation   - A valid CTM operation.
  3381. *                   CTMADD,CTMSUB,CTMMUL
  3382. *                  CTMDIV,CTMSET,CTMRESET
  3383. *
  3384. *   RESULT
  3385. *     error - RCNOERROR          if all went well.
  3386. *            RCNOMESH           if the handle is not valid.
  3387. *            RCINVALIDOPERATION if the operation is not value.
  3388. *   EXAMPLE
  3389. *    error = MWLMeshTranslationChange(meshhandle,&mytranslation,myoperation);
  3390. *
  3391. *   NOTES
  3392. *    If you pass 0 values for a division operation,
  3393. *    the corresponding CTM entry will be set to 0.
  3394. *
  3395. *   BUGS
  3396. *   SEE ALSO
  3397. *     MWLMeshCTMReset(), MWLMeshTranslationGet()
  3398. *    MWLMeshRotationChange(),MWLMeshRotationGet()
  3399. *    MWLMeshScaleChange(),MWLMeshScaleGet()
  3400. ******************************************************************************
  3401. *
  3402. */
  3403. ULONG __saveds ASM MWLMeshTranslationChange(register __d1 ULONG meshhandle,
  3404.                                             register __a0 TOCLVertex *translation,
  3405.                                             register __d2 ULONG operation) {
  3406.                                 
  3407.     TOCLMesh    *mesh=NULL;
  3408.     TOCLVertex    *tvertex=NULL;
  3409.       
  3410.     // make a copy of translation vertex, a0 is a scratch register
  3411.     tvertex=translation;
  3412.     
  3413.     mesh=(TOCLMesh *) meshhandle;
  3414.     if (mesh==NULL) return(RCNOMESH);
  3415.  
  3416.     switch (operation) {
  3417.         case CTMADD :
  3418.             mesh->ctm.m[3][0]+=tvertex->x;
  3419.             mesh->ctm.m[3][1]+=tvertex->y;
  3420.             mesh->ctm.m[3][2]+=tvertex->z;
  3421.         break;
  3422.         case CTMSUB :
  3423.             mesh->ctm.m[3][0]-=tvertex->x;
  3424.             mesh->ctm.m[3][1]-=tvertex->y;
  3425.             mesh->ctm.m[3][2]-=tvertex->z;
  3426.         break;
  3427.         case CTMMUL :
  3428.             mesh->ctm.m[3][0]*=tvertex->x;
  3429.             mesh->ctm.m[3][1]*=tvertex->y;
  3430.             mesh->ctm.m[3][2]*=tvertex->z;
  3431.         break;
  3432.         case CTMDIV :
  3433.             if(tvertex->x!=0) mesh->ctm.m[3][0]/=tvertex->x;
  3434.             else mesh->ctm.m[3][0]=0;
  3435.             if(tvertex->y!=0) mesh->ctm.m[3][1]/=tvertex->y;
  3436.             else mesh->ctm.m[3][1]=0;
  3437.             if(tvertex->z!=0) mesh->ctm.m[3][2]/=tvertex->z;
  3438.             else mesh->ctm.m[3][2]=0;
  3439.         break;
  3440.         case CTMSET :
  3441.             mesh->ctm.m[3][0]=tvertex->x;
  3442.             mesh->ctm.m[3][1]=tvertex->y;
  3443.             mesh->ctm.m[3][2]=tvertex->z;
  3444.         break;
  3445.         case CTMRESET :
  3446.             mesh->ctm.m[3][0]=0;
  3447.             mesh->ctm.m[3][1]=0;
  3448.             mesh->ctm.m[3][2]=0;
  3449.             mesh->ctm.m[3][3]=1;
  3450.         break;
  3451.         default :
  3452.             return(RCINVALIDOPERATION);
  3453.     }
  3454.  
  3455.     return(RCNOERROR);
  3456. }
  3457.  
  3458. /****** meshwriter.library/MWLMeshTranslationGet ********************************************
  3459. *   NAME    
  3460. *     MWLMeshTranslationGet -- Get the translation of the mesh its CTM.
  3461. *
  3462. *   SYNOPSIS
  3463. *    error = MWLMeshTranslationGet( meshhandle,translation )
  3464. *                                   D1          A0
  3465. *
  3466. *    ULONG MWLMeshTranslationGet
  3467. *         ( ULONG,TOCLVertex * );
  3468. *
  3469. *   FUNCTION
  3470. *    The translation of the CTM will be returned in the passed vertex structure.
  3471. *   INPUTS
  3472. *     meshhandle  - A valid handle of a mesh.
  3473. *    translation - Pointer to a vertex structure which will contain the translation.
  3474. *
  3475. *   RESULT
  3476. *     error - RCNOERROR          if all went well.
  3477. *            RCNOMESH           if the handle is not valid.
  3478. *   EXAMPLE
  3479. *    error = MWLMeshTranslationGet(meshhandle,&mytranslation);
  3480. *
  3481. *   NOTES
  3482. *
  3483. *   BUGS
  3484. *   SEE ALSO
  3485. *     MWLMeshCTMReset(), MWLMeshTranslationChange()
  3486. *    MWLMeshRotationChange(),MWLMeshRotationGet()
  3487. *    MWLMeshScaleChange(),MWLMeshScaleGet()
  3488. ******************************************************************************
  3489. *
  3490. */
  3491. ULONG __saveds ASM MWLMeshTranslationGet(register __d1 ULONG meshhandle,
  3492.                                             register __a0 TOCLVertex *translation) {
  3493.                                 
  3494.     TOCLMesh    *mesh=NULL;
  3495.     TOCLVertex    *tvertex=NULL;
  3496.       
  3497.     // make a copy of translation vertex, a0 is a scratch register
  3498.     tvertex=translation;
  3499.     
  3500.     mesh=(TOCLMesh *) meshhandle;
  3501.     if (mesh==NULL) return(RCNOMESH);
  3502.  
  3503.     tvertex->x=mesh->ctm.m[3][0];
  3504.     tvertex->y=mesh->ctm.m[3][1];
  3505.     tvertex->z=mesh->ctm.m[3][2];
  3506.     
  3507.     return(RCNOERROR);
  3508. }
  3509.  
  3510. /****** meshwriter.library/MWLMeshScaleChange ***********************************************
  3511. *   NAME    
  3512. *     MWLMeshScaleChange -- Changes the scale of the CTM of the mesh.
  3513. *
  3514. *   SYNOPSIS
  3515. *    error = MWLMeshScaleChange( meshhandle,scale,operation )
  3516. *                                D1          A0   D2
  3517. *
  3518. *    ULONG MWLMeshScaleChange
  3519. *         ( ULONG,TOCLVertex *,ULONG );
  3520. *
  3521. *   FUNCTION
  3522. *    The scale of the CTM will be modified in function of the scale
  3523. *    and the operation to perform.
  3524. *   INPUTS
  3525. *     meshhandle  - A valid handle of a mesh.
  3526. *    scale       - Pointer to a vertex structure which contains the factor
  3527. *                  of the scaling.
  3528. *    operation   - A valid CTM operation.
  3529. *                   CTMADD,CTMSUB,CTMMUL
  3530. *                  CTMDIV,CTMSET,CTMRESET
  3531. *
  3532. *   RESULT
  3533. *     error - RCNOERROR          if all went well.
  3534. *            RCNOMESH           if the handle is not valid.
  3535. *            RCINVALIDOPERATION if the operation is not value.
  3536. *   EXAMPLE
  3537. *    error = MWLMeshScaleChange(meshhandle,&myscale,myoperation);
  3538. *
  3539. *   NOTES
  3540. *    If you pass 0 values for a division operation,
  3541. *    the corresponding CTM entry will be set to 0.
  3542. *
  3543. *   BUGS
  3544. *   SEE ALSO
  3545. *     MWLMeshTranslationChange(), MWLMeshTranslationGet()
  3546. *    MWLMeshRotationChange(),MWLMeshRotationGet()
  3547. *    MWLMeshCTMReset(),MWLMeshScaleGet()
  3548. ******************************************************************************
  3549. *
  3550. */
  3551. ULONG __saveds ASM MWLMeshScaleChange(register __d1 ULONG meshhandle,
  3552.                                             register __a0 TOCLVertex *scale,
  3553.                                             register __d2 ULONG operation) {
  3554.                                 
  3555.     TOCLMesh    *mesh=NULL;
  3556.     TOCLVertex    *svertex=NULL;
  3557.       
  3558.     // make a copy of scale vertex, a0 is a scratch register
  3559.     svertex=scale;
  3560.     
  3561.     mesh=(TOCLMesh *) meshhandle;
  3562.     if (mesh==NULL) return(RCNOMESH);
  3563.  
  3564.     switch (operation) {
  3565.         case CTMADD :
  3566.             mesh->ctm.sx+=svertex->x;
  3567.             mesh->ctm.sy+=svertex->y;
  3568.             mesh->ctm.sz+=svertex->z;
  3569.         break;
  3570.         case CTMSUB :
  3571.             mesh->ctm.sx-=svertex->x;
  3572.             mesh->ctm.sy-=svertex->y;
  3573.             mesh->ctm.sz-=svertex->z;
  3574.         break;
  3575.         case CTMMUL :
  3576.             mesh->ctm.sx*=svertex->x;
  3577.             mesh->ctm.sy*=svertex->y;
  3578.             mesh->ctm.sz*=svertex->z;
  3579.         break;
  3580.         case CTMDIV :
  3581.             if(svertex->x!=0) mesh->ctm.sx/=svertex->x;
  3582.             else mesh->ctm.sx=0;
  3583.             if(svertex->y!=0) mesh->ctm.sy/=svertex->y;
  3584.             else mesh->ctm.sy=0;
  3585.             if(svertex->z!=0) mesh->ctm.sz/=svertex->z;
  3586.             else mesh->ctm.sz=0;
  3587.         break;
  3588.         case CTMSET :
  3589.             mesh->ctm.sx=svertex->x;
  3590.             mesh->ctm.sy=svertex->y;
  3591.             mesh->ctm.sz=svertex->z;
  3592.         break;
  3593.         case CTMRESET :
  3594.             mesh->ctm.sx=1;
  3595.             mesh->ctm.sy=1;
  3596.             mesh->ctm.sz=1;
  3597.         break;
  3598.         default :
  3599.             return(RCINVALIDOPERATION);
  3600.     }
  3601.  
  3602.     return(RCNOERROR);
  3603. }
  3604.  
  3605. /****** meshwriter.library/MWLMeshScaleGet **************************************************
  3606. *   NAME    
  3607. *     MWLMeshScaleGet -- Get the scale of the mesh its CTM.
  3608. *
  3609. *   SYNOPSIS
  3610. *    error = MWLMeshScaleGet( meshhandle,scale )
  3611. *                             D1          A0
  3612. *
  3613. *    ULONG MWLMeshScaleGet
  3614. *         ( ULONG,TOCLVertex * );
  3615. *
  3616. *   FUNCTION
  3617. *    The scale of the CTM will be returned in the passed vertex structure.
  3618. *   INPUTS
  3619. *     meshhandle  - A valid handle of a mesh.
  3620. *    scale       - Pointer to a vertex structure which will contain the scale factors.
  3621. *
  3622. *   RESULT
  3623. *     error - RCNOERROR          if all went well.
  3624. *            RCNOMESH           if the handle is not valid.
  3625. *   EXAMPLE
  3626. *    error = MWLMeshScaleGet(meshhandle,&myscale);
  3627. *
  3628. *   NOTES
  3629. *
  3630. *   BUGS
  3631. *   SEE ALSO
  3632. *     MWLMeshTranslationChange(), MWLMeshTranslationChange()
  3633. *    MWLMeshRotationChange(),MWLMeshRotationGet()
  3634. *    MWLMeshScaleChange(),MWLMeshCTMReset()
  3635. ******************************************************************************
  3636. *
  3637. */
  3638. ULONG __saveds ASM MWLMeshScaleGet(register __d1 ULONG meshhandle,
  3639.                                     register __a0 TOCLVertex *scale) {
  3640.                                 
  3641.     TOCLMesh    *mesh=NULL;
  3642.     TOCLVertex    *svertex=NULL;
  3643.       
  3644.     // make a copy of scale vertex, a0 is a scratch register
  3645.     svertex=scale;
  3646.     
  3647.     mesh=(TOCLMesh *) meshhandle;
  3648.     if (mesh==NULL) return(RCNOMESH);
  3649.  
  3650.     svertex->x=mesh->ctm.sx;
  3651.     svertex->y=mesh->ctm.sy;
  3652.     svertex->z=mesh->ctm.sz;
  3653.     
  3654.     return(RCNOERROR);
  3655. }
  3656.  
  3657. /****** meshwriter.library/MWLMeshRotationChange ********************************************
  3658. *   NAME    
  3659. *     MWLMeshRotationChange -- Changes the rotation of the CTM of the mesh.
  3660. *
  3661. *   SYNOPSIS
  3662. *    error = MWLMeshRotationChange( meshhandle,rotation,operation )
  3663. *                                   D1          A0      D2
  3664. *
  3665. *    ULONG MWLMeshRotationChange
  3666. *         ( ULONG,TOCLVertex *,ULONG );
  3667. *
  3668. *   FUNCTION
  3669. *    The rotation of the CTM will be modified in function of the rotation
  3670. *    and the operation to perform.
  3671. *   INPUTS
  3672. *     meshhandle - A valid handle of a mesh.
  3673. *    rotation   - Pointer to a vertex structure which contains the angles in radian
  3674. *                 of the rotation.
  3675. *    operation  - A valid CTM operation.
  3676. *                  CTMADD,CTMSUB,CTMMUL
  3677. *                 CTMDIV,CTMSET,CTMRESET
  3678. *
  3679. *   RESULT
  3680. *     error - RCNOERROR          if all went well.
  3681. *            RCNOMESH           if the handle is not valid.
  3682. *            RCINVALIDOPERATION if the operation is not value.
  3683. *   EXAMPLE
  3684. *    error = MWLMeshRotationChange(meshhandle,&myrotation,myoperation);
  3685. *
  3686. *   NOTES
  3687. *    If you pass 0 values for a division operation,
  3688. *    the corresponding CTM entry will be set to 0.
  3689. *
  3690. *   BUGS
  3691. *   SEE ALSO
  3692. *     MWLMeshTranslationChange(), MWLMeshTranslationGet()
  3693. *    MWLMeshCTMReset(),MWLMeshRotationGet()
  3694. *    MWLMeshScaleChange(),MWLMeshScaleGet()
  3695. ******************************************************************************
  3696. *
  3697. */
  3698. ULONG __saveds ASM MWLMeshRotationChange(register __d1 ULONG meshhandle,
  3699.                                             register __a0 TOCLVertex *rotation,
  3700.                                             register __d2 ULONG operation) {
  3701.                                 
  3702.     TOCLMesh    *mesh=NULL;
  3703.     TOCLVertex    *rvertex=NULL;
  3704.     double        m1[3][3],m2[3][3];
  3705.       
  3706.     // make a copy of rotation vertex, a0 is a scratch register
  3707.     rvertex=rotation;
  3708.     
  3709.     mesh=(TOCLMesh *) meshhandle;
  3710.     if (mesh==NULL) return(RCNOMESH);
  3711.  
  3712.     switch (operation) {
  3713.         case CTMADD :
  3714.             mesh->ctm.rx+=rvertex->x;
  3715.             mesh->ctm.ry+=rvertex->y;
  3716.             mesh->ctm.rz+=rvertex->z;
  3717.         break;
  3718.         case CTMSUB :
  3719.             mesh->ctm.rx-=rvertex->x;
  3720.             mesh->ctm.ry-=rvertex->y;
  3721.             mesh->ctm.rz-=rvertex->z;
  3722.         break;
  3723.         case CTMMUL :
  3724.             mesh->ctm.rx*=rvertex->x;
  3725.             mesh->ctm.ry*=rvertex->y;
  3726.             mesh->ctm.rz*=rvertex->z;
  3727.         break;
  3728.         case CTMDIV :
  3729.             if(rvertex->x!=0) mesh->ctm.rx/=rvertex->x;
  3730.             else mesh->ctm.rx=0;
  3731.             if(rvertex->y!=0) mesh->ctm.ry/=rvertex->y;
  3732.             else mesh->ctm.ry=0;
  3733.             if(rvertex->z!=0) mesh->ctm.rz/=rvertex->z;
  3734.             else mesh->ctm.rz=0;
  3735.         break;
  3736.         case CTMSET :
  3737.             mesh->ctm.rx=rvertex->x;
  3738.             mesh->ctm.ry=rvertex->y;
  3739.             mesh->ctm.rz=rvertex->z;
  3740.         break;
  3741.         case CTMRESET :
  3742.             mesh->ctm.rx=0;
  3743.             mesh->ctm.ry=0;
  3744.             mesh->ctm.rz=0;
  3745.         break;
  3746.         default :
  3747.             return(RCINVALIDOPERATION);
  3748.     }
  3749.  
  3750.     // If equal to 2*PI set to 0
  3751.     if(mesh->ctm.rx==2*PI) mesh->ctm.rx=0;
  3752.     if(mesh->ctm.ry==2*PI) mesh->ctm.ry=0;
  3753.     if(mesh->ctm.rz==2*PI) mesh->ctm.rz=0;
  3754.  
  3755.     // Recalculating the CTM
  3756.     m1[0][0]=1;
  3757.     m1[1][0]=0;
  3758.     m1[2][0]=0;
  3759.     m1[0][1]=0;
  3760.     m1[1][1]=1;
  3761.     m1[2][1]=0;
  3762.     m1[0][2]=0;
  3763.     m1[1][2]=0;
  3764.     m1[2][2]=1;
  3765.  
  3766.     m2[0][0]=cos(mesh->ctm.rz);
  3767.     m2[1][0]=-sin(mesh->ctm.rz);
  3768.     m2[2][0]=0;
  3769.     m2[0][1]=sin(mesh->ctm.rz);
  3770.     m2[1][1]=cos(mesh->ctm.rz);
  3771.     m2[2][1]=0;
  3772.     m2[0][2]=0;
  3773.     m2[1][2]=0;
  3774.     m2[2][2]=1;
  3775.  
  3776.     mulMatrix(m1,m2);
  3777.  
  3778.     m2[0][0]=cos(mesh->ctm.ry);
  3779.     m2[1][0]=0;
  3780.     m2[2][0]=sin(mesh->ctm.ry);
  3781.     m2[0][1]=0;
  3782.     m2[1][1]=1;
  3783.     m2[2][1]=0;
  3784.     m2[0][2]=-sin(mesh->ctm.ry);
  3785.     m2[1][2]=0;
  3786.     m2[2][2]=cos(mesh->ctm.ry);
  3787.  
  3788.     mulMatrix(m1,m2);
  3789.  
  3790.     m2[0][0]=1;
  3791.     m2[1][0]=0;
  3792.     m2[2][0]=0;
  3793.     m2[0][1]=0;
  3794.     m2[1][1]=cos(mesh->ctm.rx);
  3795.     m2[2][1]=-sin(mesh->ctm.rx);
  3796.     m2[0][2]=0;
  3797.     m2[1][2]=sin(mesh->ctm.rx);
  3798.     m2[2][2]=cos(mesh->ctm.rx);
  3799.  
  3800.     mulMatrix(m1,m2);
  3801.  
  3802.     mesh->ctm.m[0][0]=(TOCLFloat)m1[0][0];
  3803.     mesh->ctm.m[1][0]=(TOCLFloat)m1[1][0];
  3804.     mesh->ctm.m[2][0]=(TOCLFloat)m1[2][0];
  3805.     mesh->ctm.m[0][1]=(TOCLFloat)m1[0][1];
  3806.     mesh->ctm.m[1][1]=(TOCLFloat)m1[1][1];
  3807.     mesh->ctm.m[2][1]=(TOCLFloat)m1[2][1];
  3808.     mesh->ctm.m[0][2]=(TOCLFloat)m1[0][2];
  3809.     mesh->ctm.m[1][2]=(TOCLFloat)m1[1][2];
  3810.     mesh->ctm.m[2][2]=(TOCLFloat)m1[2][2];
  3811.  
  3812.     return(RCNOERROR);
  3813. }
  3814.  
  3815. /****** meshwriter.library/MWLMeshRotationGet ***********************************************
  3816. *   NAME    
  3817. *     MWLMeshRotationGet -- Get the rotation of the mesh its CTM.
  3818. *
  3819. *   SYNOPSIS
  3820. *    error = MWLMeshRotationGet( meshhandle,rotation )
  3821. *                                D1          A0
  3822. *
  3823. *    ULONG MWLMeshRotationGet
  3824. *         ( ULONG,TOCLVertex * );
  3825. *
  3826. *   FUNCTION
  3827. *    The rotation of the CTM will be returned in the passed vertex structure.
  3828. *   INPUTS
  3829. *     meshhandle - A valid handle of a mesh.
  3830. *    rotation   - Pointer to a vertex structure which will contain the
  3831. *                 rotation angles in radian.
  3832. *
  3833. *   RESULT
  3834. *     error - RCNOERROR          if all went well.
  3835. *            RCNOMESH           if the handle is not valid.
  3836. *   EXAMPLE
  3837. *    error = MWLMeshRotationGet(meshhandle,&myrotation);
  3838. *
  3839. *   NOTES
  3840. *
  3841. *   BUGS
  3842. *   SEE ALSO
  3843. *     MWLMeshtranslationChange(), MWLMeshTranslationChange()
  3844. *    MWLMeshRotationChange(),MWLMeshCTMReset()
  3845. *    MWLMeshScaleChange(),MWLMeshScaleGet()
  3846. ******************************************************************************
  3847. *
  3848. */
  3849. ULONG __saveds ASM MWLMeshRotationGet(register __d1 ULONG meshhandle,
  3850.                                         register __a0 TOCLVertex *rotation) {
  3851.                                 
  3852.     TOCLMesh    *mesh=NULL;
  3853.     TOCLVertex    *rvertex=NULL;
  3854.       
  3855.     // make a copy of rotation vertex, a0 is a scratch register
  3856.     rvertex=rotation;
  3857.     
  3858.     mesh=(TOCLMesh *) meshhandle;
  3859.     if (mesh==NULL) return(RCNOMESH);
  3860.  
  3861.     rvertex->x=mesh->ctm.rx;
  3862.     rvertex->y=mesh->ctm.ry;
  3863.     rvertex->z=mesh->ctm.rz;
  3864.     
  3865.     return(RCNOERROR);
  3866. }
  3867. /****** meshwriter.library/MWLMeshMaterialDiffuseColorSet ******************************************
  3868. *   NAME    
  3869. *     MWLMeshMaterialDiffuseColorSet -- Set the diffuse color of a material.
  3870. *   SYNOPSIS
  3871. *    error = MWLMeshMaterialDiffuseColorSet( meshhandle,materialhandle,color )
  3872. *                                            D1         D2              A0
  3873. *
  3874. *    ULONG MWLMeshMaterialDiffuseColorSet
  3875. *         ( ULONG,ULONG,TOCLColor * );
  3876. *
  3877. *   FUNCTION
  3878. *    The diffuse color of the material will be set to the values passed by the
  3879. *    color structure.
  3880. *   INPUTS
  3881. *     meshhandle      - A valid handle of a mesh.
  3882. *    materialhandle  - A valid handle of a material.
  3883. *    color           - Pointer to a color structure containing the color information.
  3884. *    
  3885. *   RESULT
  3886. *     error - RCNOERROR    if all went well.
  3887. *            RCNOMESH     if the handle is not valid.
  3888. *            RCNOMATERIAL if the handle is not valid.
  3889. *
  3890. *   EXAMPLE
  3891. *    error = MWLMeshMaterialDiffuseColorSet(meshhandle,materialhandle,&mycolor);
  3892. *
  3893. *   NOTES
  3894. *
  3895. *   BUGS
  3896. *   SEE ALSO
  3897. *     MWLMeshMaterialDiffuseColorGet()
  3898. ******************************************************************************
  3899. *
  3900. */
  3901. ULONG __saveds ASM MWLMeshMaterialDiffuseColorSet(register __d1 ULONG meshhandle,
  3902.                                                         register __d2 ULONG materialhandle,
  3903.                                                         register __a0 TOCLColor *color) {
  3904.     TOCLMesh            *mesh=NULL;
  3905.     TOCLMaterialNode    *mat=NULL;
  3906.     TOCLColor            *mcolor=NULL;
  3907.  
  3908.     // make a copy of color, because a0 is a scratch register
  3909.     mcolor = color;
  3910.     
  3911.     mesh=(TOCLMesh *) meshhandle;
  3912.     if(mesh==NULL) return(RCNOMESH);
  3913.   
  3914.     mat=getMaterialNode(mesh,materialhandle);
  3915.     if(mat==NULL) return(RCNOMATERIAL);
  3916.   
  3917.     mat->diffuseColor=(*mcolor);
  3918.     
  3919.     return(RCNOERROR);
  3920. }
  3921.  
  3922. /****** meshwriter.library/MWLMeshMaterialDiffuseColorGet ******************************************
  3923. *   NAME    
  3924. *     MWLMeshMaterialDiffuseColorGet -- Get the diffuse color of a material.
  3925. *   SYNOPSIS
  3926. *    error = MWLMeshMaterialDiffuseColorGet( meshhandle,materialhandle,color )
  3927. *                                            D1         D2              A0
  3928. *
  3929. *    ULONG MWLMeshMaterialDiffuseColorGet
  3930. *         ( ULONG,ULONG,TOCLColor * );
  3931. *
  3932. *   FUNCTION
  3933. *    The diffuse color of the material will be written in the passed color structure.
  3934. *   INPUTS
  3935. *     meshhandle      - A valid handle of a mesh.
  3936. *    materialhandle  - A valid handle of a material.
  3937. *    color           - Pointer to a color structure which will contain
  3938. *                      the color information.
  3939. *    
  3940. *   RESULT
  3941. *     error - RCNOERROR    if all went well.
  3942. *            RCNOMESH     if the handle is not valid.
  3943. *            RCNOMATERIAL if the handle is not valid.
  3944. *
  3945. *   EXAMPLE
  3946. *    error = MWLMeshMaterialDiffuseColorGet(meshhandle,materialhandle,&mycolor);
  3947. *
  3948. *   NOTES
  3949. *
  3950. *   BUGS
  3951. *   SEE ALSO
  3952. *     MWLMeshMaterialDiffuseColorSet()
  3953. ******************************************************************************
  3954. *
  3955. */
  3956. ULONG __saveds ASM MWLMeshMaterialDiffuseColorGet(register __d1 ULONG meshhandle,
  3957.                                                         register __d2 ULONG materialhandle,
  3958.                                                         register __a0 TOCLColor *color) {
  3959.     TOCLMesh            *mesh=NULL;
  3960.     TOCLMaterialNode    *mat=NULL;
  3961.     TOCLColor            *mcolor=NULL;
  3962.     
  3963.     // make a copy of color, a0 is a scratch register
  3964.     mcolor=color;
  3965.     
  3966.     mesh=(TOCLMesh *) meshhandle;
  3967.     if(mesh==NULL) return(RCNOMESH);
  3968.   
  3969.     mat=getMaterialNode(mesh,materialhandle);
  3970.     if(mat==NULL) return(RCNOMATERIAL);
  3971.   
  3972.     (*mcolor)=mat->diffuseColor;
  3973.     
  3974.     return(RCNOERROR);
  3975. }
  3976.  
  3977. /*
  3978. TODO
  3979.  
  3980. Lightwave,Imagine,Videoscape  groessen/anzahl checks fertigmachen !!
  3981.  
  3982. Material mehr parameter, brechungsindex, reflektion, ...
  3983.  
  3984. */
  3985.  
  3986. /************************* End of file ******************************/
  3987.  
  3988.